[Selenium]Turn Page By Scroll Bar
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******************************/
[Selenium]Turn Page By Scroll Bar的更多相关文章
- Selenium - IWebDriver 控制scroll bar到底部
有时候我们需要控制页面滚动条上的滚动条,但滚动条并非页面上的元素,这个时候就需要借助js是来进行操作.一般用到操作滚动条的会两个场景: 注册时的法律条文需要阅读,判断用户是否阅读的标准是:滚动条是否拉 ...
- 浅析selenium的page object模式
selenium目前比较流行的设计模式就是page object,那么到底什么是page object呢,简单来说,就是把页面作为对象,在使用中传递页面对象,来使用页面对象中相应的成员或者方法,能更好 ...
- VS2010/MFC编程入门之二十六(常用控件:滚动条控件Scroll Bar)
回顾上一节,鸡啄米讲的是组合框控件Combo Box的使用.本节详解滚动条控件Scroll Bar的相关内容. 滚动条控件简介 滚动条大家也很熟悉了,Windows窗口中很多都有滚动条.前面讲的列表框 ...
- (七)对话框,单选框(radiobox),复选框(checkbox),列表框(ListBox),组合框(CComboBox),水平滚动条(Horizontal scroll bar),微调(旋转)spincontrol,列表视图控件CListCtrl,静态控件static
1,模态对话框和非模态对话框 // 模态对话框 void CMainFrame::OnDialogExec() { // TODO: 在此添加命令处理程序代码 // 创建对话框对象 CDialog d ...
- NGUI多行输入框和滚动条结合使用(text list script 和scroll bar script)
一,我们添加一个label,如下图:将label属性设置 二,给label添加一个box collider.然后在add component 添加test list,如下图: 三,添加一个脚本Test ...
- NGUI的滚动条的制作(scroll bar script)
一,我们添加一个sprite,添加一个box collider,然后添加一个scroll bar script,我们来看看scroll bar script的属性 看到background和forgr ...
- VS2010-MFC(常用控件:滚动条控件Scroll Bar)
转自:http://www.jizhuomi.com/software/191.html 滚动条控件简介 滚动条大家也很熟悉了,Windows窗口中很多都有滚动条.前面讲的列表框和组合框设置了相应属性 ...
- Python+Selenium使用Page Object实现页面自动化测试
Page Object模式是Selenium中的一种测试设计模式,主要是将每一个页面设计为一个Class,其中包含页面中需要测试的元素(按钮,输入框,标题 等),这样在Selenium测试页面中可以通 ...
- Selenium关于Page Objects
介绍页面对象设计模式.一个页面对象表示在你测试的web页面用户交互的界面. 使用页面对象模式的有点: 创建可重用的代码可以在多个测试用例中使用 减少重复的代码量 如果用户界面改变,只需要修改一个地方 ...
随机推荐
- C#修改注册表
某次需要使用C#对注册表进行操作,不过却发现没有权限,研究了以下发现是当前系统用户的问题.除非当前系统用户是Administrator,否则就会给你抛出一个异常.后来在网上发现了一个方法,原来C#也可 ...
- Dijkstra算法(C语言)
Dijkstra算法 1.定义概览 Dijkstra(迪杰斯特拉)算法是典型的单源最短路径算法,用于计算一个节点到其他所有节点的最短路径.主要特点是以起始点为中心向外层层扩展,直到扩展到终点为止.Di ...
- Oracle Client 10g (instantclient) 精简版安装
今天遇到个软件要求安装oracle client端,于是考虑装精简版本的,就从http://www.oracle.com/technology/software/tech/oci/instantcli ...
- github之本地上传
在打算上传到github之前需要在github上面首先创建一个项目(点击右上角“+”号,点击New repository):
- 解决一个java facets问题
经常被一个问题困扰: JavaServer Faces 2.2 can not be installed : One or more constraints have not been satisfi ...
- mamp下安装ruby的mysql库
mysql2库死活不行,用ruby-mysql得了,纯ruby的库 gem "ruby-mysql" require 'mysql'
- [转]JavaScript RegExp 对象参考手册
JavaScript RegExp 对象参考手册 RegExp 对象 RegExp 对象表示正则表达式,它是对字符串执行模式匹配的强大工具. 直接量语法 /pattern/attributes 创建 ...
- 图搜索——使用DFS和BFS耗时比较
图测试数据生成代码: #include<bits/stdc++.h> using namespace std; int random(int mod) { return rand() % ...
- 测试工具-PICT-微软基于数据项多个取值的正交法用例生成工具
下载 http://download.microsoft.com/download/f/5/5/f55484df-8494-48fa-8dbd-8c6f76cc014b/pict33.msi 这里使用 ...
- 深度解析Java中的那把锁
锁的本质 我们先来讨论锁的出现是为了解决什么问题,锁要保证的事情其实很好理解,同一件事(一个代码块)在同一时刻只能由一个人(线程)操作. 这里所说的锁为排他锁,暂不考虑读写锁的情况 我们在这里打个比方 ...