【转】selenium技巧 - 通过js来控制滚动条,通过xpath定位最上层的div层
http://blog.csdn.net/iceryan/article/details/8162703


- package com.example.tests;
- import org.junit.*;
- import org.openqa.selenium.*;
- import org.openqa.selenium.ie.InternetExplorerDriver;
- public class SeleniumWebDriver {
- public static WebDriver driver;
- @Test
- public void testUnit() {
- driver = new InternetExplorerDriver();
- driver.get("http://nanjing.xiaomishu.com/shop/search/sp2048_745");
- maxBrowser(driver);
- setScroll(driver,500);
- driver.findElement(By.linkText("投诉与建议")).click();
- driver.findElement(By.xpath("//input[@id='repName']")).sendKeys("1");
- driver.findElement(By.xpath("//input[@id='repMail']")).sendKeys("1");
- driver.findElement(By.xpath("//textarea[@id='repContent']")).sendKeys("hello");
- driver.findElement(By.xpath("//a[@id='repBtn']")).click();
- Assert.assertEquals("您输入的邮箱格式不正确", driver.findElement(By.xpath("//div[@id='floatBox_remind']/span")).getText());
- }
- //将IE最大化
- public static void maxBrowser(WebDriver driver){
- try {
- String maxBroswer = "if (window.screen) {window.moveTo(0, 0);" +
- "window.resizeTo(window.screen.availWidth,window.screen.availHeight);}";
- JavascriptExecutor jse=(JavascriptExecutor) driver;
- jse.executeScript(maxBroswer);
- } catch (Exception e) {
- System.out.println("Fail to Maximization browser");
- }
- }
- //将滚动条滚到适合的位置
- public static void setScroll(WebDriver driver,int height){
- try {
- String setscroll = "document.documentElement.scrollTop=" + height;
- JavascriptExecutor jse=(JavascriptExecutor) driver;
- jse.executeScript(setscroll);
- } catch (Exception e) {
- System.out.println("Fail to set the scroll.");
- }
- }
- }
【转】selenium技巧 - 通过js来控制滚动条,通过xpath定位最上层的div层的更多相关文章
- selenium执行JavaScript语句:控制滚动条 聚焦元素 改变下拉选项
1. 执行js脚本 控制滚动条 # http://www.cnblogs.com/yoyoketang/p/6128655.html In [347]: js = "window.scrol ...
- java selenium webdriver处理JS操作窗口滚动条
未经作者允许,禁止转载!!! java selenium webdriver处理JS操作窗口滚动条 java selenium webdriver处理JS操作窗口滚动条 import org.open ...
- Python selenium webdriver设置js操作页面滚动条
js2 = "window.scrollTo(0,0);" #括号中为坐标 当不知道需要的滚动的坐标大小时: weizhi2 = driver.find_element_by_id ...
- 2018年 js 简易控制滚动条滚动的简单方法
首先是es2015 的新api Element.scrollIntoView() // 滚动到最上方 等同于 dom.scrollIntoView(true) Element.scrollIntoVi ...
- Java&Selenium控制滚动条方法封装
Java&Selenium控制滚动条方法封装 package util; import org.openqa.selenium.JavascriptExecutor; import org.o ...
- 【python+selenium的web自动化】- 控制浏览器的常用操作
如果想从头学起selenium,可以去看看这个系列的文章哦! https://www.cnblogs.com/miki-peng/category/1942527.html 前言 本文主要介绍se ...
- Selenium(十三)调用js,控制浏览器的滚动条
WebDiver 不能操作本地 Windows 控件,但对于浏览器上的控件也不是都可以操作的.比如浏览器的滚动条,虽然 WebDriver 提供操作浏览器的前进和后退按钮,但对于滚动条并没有提供相应用 ...
- 使用selenium控制滚动条(非整屏body)
方法原理: (1)使用jQuery CSS 操作 - scrollTop() 方法,设置 <div> 元素中滚动条的垂直偏移,语法:$(selector).scrollTop(of ...
- selenium自动化之js处理滚动条和元素聚焦
selenium并不是万能的,有时候页面上操作无法实现的,这时候就需要借助JS来完成了. 当我们页面上的元素超过一屏后,想操作屏幕下方的元素,是不能直接操作的,会报元素不可见异常的.这时候需要借助滚动 ...
随机推荐
- springboot#配置https
1.准备证书 2.1 springboot 1.x配置 2.2 springboot 2.x配置 1.准备证书: keytool -genkeypair -alias tomcat -keyalg R ...
- ng -----监听变化($scope.$watch())
需求:项目组件中遇到改变日期触发方法. 困难:日期组件中不涉及释焦功能 解决:在angularjs中用$scope.$watch() 其中name是字符串,是指监听到的具体对象值.
- SpringBoot 入门demo
创建SpringBoot项目方式一 (1)新建maven项目,不使用骨架. 使用maven管理依赖就行了,不必使用骨架(模板). (2)在pom.xml中添加 <!--springboot核心. ...
- IOS导航器 + 表控制器 常用功能函数/属性
1. 设置标题栏(顶部)颜色 在表控制器中 e.g -(void)viewDidLoad中添加 self.navigationController.navigationBar.barTintColor ...
- Lesson 6 The sporting spirit
How does the writer describe sport at the international level? I am always amazed when I hear people ...
- 连接数据库 - (mysql-thinkphp) (2)
1.现在conf里面写好选择的数据库 选择好了以后 2.在index里面输入 查询mysql数据库里面的表tables_priv的所有数据 public function index() { $res ...
- 在 Scale Up 中使用 Health Check【转】
对于多副本应用,当执行 Scale Up 操作时,新副本会作为 backend 被添加到 Service 的负载均衡中,与已有副本一起处理客户的请求.考虑到应用启动通常都需要一个准备阶段,比如加载缓存 ...
- Day5 - H - Supermarket POJ - 1456
A supermarket has a set Prod of products on sale. It earns a profit px for each product x∈Prod sold ...
- 移动端 三段式布局 (flex方式)
分享一种平时用的三段式布局(flex) 主要思路是 上中下 header&footer 给高度 main 占其余部分 html 部分 <div class='wrap'> ...
- Spark 资料整理
http://jerryshao.me/architecture/2013/10/08/spark-storage-module-analysis/ http://blog.csdn.net/aliv ...