[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页面用户交互的界面. 使用页面对象模式的有点: 创建可重用的代码可以在多个测试用例中使用 减少重复的代码量 如果用户界面改变,只需要修改一个地方 ...
随机推荐
- Python面试题(十六)
1.取出两个升序数组中的最小的一半的元素组成一个新的升序数组. map(lambda x, y: x if x < y else y, a, b) 答案 2.用至少2种不同的方式删除一个list ...
- 【linux】mkdir -p命令
如果要创建目录A并创建目录A的子目录B,没有用-p的情况下是mkdir 2次 如果用-p 可以直接创建2个目录 (迭代创建).mkdir -p 目录A/子目录B就可以
- HBuilder webApp开发 Websql增删改查操作
来源:http://blog.csdn.net/zhuming3834/article/details/51471434 这段时间公司要求我们做原生iOS和安卓的都转做H5开发APP,使用的工具HBu ...
- wamp 配置多站点访问
1:在f:\wamp\bin\apache\apache2.2.21\conf目录下打开 httpd.conf 查找到 #include conf/extra/httpd-vhosts.conf 把前 ...
- postman-2get发送请求
文档地址:https://www.v2ex.com/p/7v9TEc53 第一个API请求 最热主题 相当于首页右侧的 10 大每天的内容. https://www.v2ex.com/api/topi ...
- JMS消息模型
消息机制: 系统之间通信的中介,作为一台单独的服务器部署,大多数使用多个系统之间协作,是系统解耦的常见解决方案. 基于CS架构 作用:多个系统之间解耦,项目可以分开开发,满足显示的高可用(也可以说是异 ...
- uwsgi的python2+3多版本共存实操使用virtualenv
1首先,机器需要有python2和python3的可执行环境.确保pip和pip3命令可用.原理就是在哪个环境下安装uwsgi.uwsgi启动的时候,就用的哪个python版本 2安装virtuale ...
- [代码][deque容器练习]打分案例
案例要求: //打分案例(sort算法排序)//创建5个选手(姓名.得分),十个评委对五个选手进行打分//得分规则:去除最高分,去除最低分,取出平均分//按得分对5个选手进行排名 源代码: //打分案 ...
- react之echarts数据更新
react之echarts数据更新 在使用setState更新数据时,如果要将图标更新,需要做一些简单的封装,代码如下: import React, { Component } from 'react ...
- ASPxGridView删除、添加、修改成功后,弹出提示对话框的方法
分为几步: 1.在aspx文件中添加 function EndCallBack(s, e) { if (s.cpAlertMsg != "" && s.cpA ...