Description:
Need to turn page by operating scroll bar and find out the element in the current page.
Previous page will not exist in DOM structure when turning page.
Solution:
- Get the total height, button height, scroll bar height
- Calculate total move height, totalMoveHeight = totalHeight - 2*buttonHeight - scrollbarHeight
- Calculate page number, pageNum = ?totalMoveHeight/scrollbarHeight
- Calculate the last page when it is less then a whole page, lessThenOnePageHeight = totalMoveHeight%scrollbarHeight
- Turn page according to the page number and lessThenOnePageHeight
Code:
/**************************Report Portal–>ReportProductionFlow.java******************************/ public void seleteTemplate_NotClassifiedFactsheet(String template){ //Scroll the scroll bar page by page Actions actions = new Actions(page.getDriver()); int totalHeight = page.getDiv_scrollbar_TemplateMappingSetting().getSize().getHeight(); int buttonHeight = page.getButton_ScrollbarDown().getSize().getHeight(); int scrollbarHeight = page.getScrollbar_TemplateMappingSetting().getSize().getHeight(); int totalMoveHeight = totalHeight - buttonHeight - buttonHeight - scrollbarHeight; int pageNum = totalMoveHeight/scrollbarHeight; int lessThenOnePageHeight = totalMoveHeight%scrollbarHeight; if(lessThenOnePageHeight>0){ pageNum+=1; } for(int i=0;i<pageNum;i++){ if ((i==(pageNum-1))&&(lessThenOnePageHeight>0)) { scrollbarHeight=lessThenOnePageHeight; } actions.dragAndDropBy(page.getScrollbar_TemplateMappingSetting(), 0, scrollbarHeight).perform(); SeleniumUtil.sleep(1); List <WebElement> groupList = page.getGroupListInTemplateMapping(); int groupNum = groupList.size(); for(int j=0;j<groupNum;j++){ WebElement groupEl=groupList.get(j); String groupName = groupEl.getText(); if(groupName.equals("Not Classified")){ System.out.println("Find Group : "+groupName+" in page "+i); WebElement factsheetTemplateEl=page.getDDL_NotClassifiedFactsheet(); factsheetTemplateEl.click(); page.getLink_Template(template).click(); } } } } /**************************Report Portal–>ReportProductionFlow.java******************************/
?
/**************************Report Portal–>ReportProductionPage.java******************************/ public WebElement getDiv_scrollbar_TemplateMappingSetting(){ return SeleniumUtil.waitForElementPresent(driver, By.cssSelector("div#uidialog7.uidialog div.uidialogcontent div#mapEditDlgDiv div.tempmapsetup div.itemsgrid div.rtq-grid div.rtq-grid-sz div.rtq-scrollpanel div.rtq-scrollbar.rtq-scrollbar-y")); } public WebElement getButton_ScrollbarDown(){ return SeleniumUtil.waitForElementPresent(driver, By.cssSelector("div#uidialog7.uidialog div.uidialogcontent div#mapEditDlgDiv div.tempmapsetup div.itemsgrid div.rtq-grid div.rtq-grid-sz div.rtq-scrollpanel div.rtq-scrollbar.rtq-scrollbar-y a.rtq-scrollbar-down")); } public WebElement getScrollbar_TemplateMappingSetting(){ return SeleniumUtil.waitForElementPresent(driver, By.cssSelector("div#uidialog7.uidialog div.uidialogcontent div#mapEditDlgDiv div.tempmapsetup div.itemsgrid div.rtq-grid div.rtq-grid-sz div.rtq-scrollpanel div.rtq-scrollbar.rtq-scrollbar-y div.rtq-scrollbar-bar")); } /**************************Report Portal–>ReportProductionFlow.java******************************/
?
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
