等待

页面全加载

ChromeOptions options=new ChromeOptions();
/**
*(1) NONE: 当html下载完成之后,不等待解析完成,selenium会直接返回
*(2) EAGER: 要等待整个dom树加载完成,即DOMContentLoaded这个事件完成,仅对html的内容进行下载解析
*(3) NORMAL: 即正常情况下,selenium会等待整个界面加载完成(指对html和子资源的下载与解析,如JS文件,图片等,不包括ajax)
*/
options.setPageLoadStrategy(PageLoadStrategy.NONE);
//添加参数,关闭拦截弹窗
options.addArguments("disable-popup-blocking");
options.addArguments("disable-notifications");
//关闭被自动化控制的提示
options.addArguments("disable-infobars");
options.addArguments("disable-extensions");
options.addArguments("start-maximized"); driver = new ChromeDriver(options);
private void Form1_Load(object sender, EventArgs e)
{
ChromeOptions options = new ChromeOptions();
options.AddArguments("--disable-extensions"); // to disable extension
options.AddArguments("--disable-notifications"); // to disable notification
options.AddArguments("--disable-application-cache"); // to disable cache
options.AddArgument("--safebrowsing-disable-download-protection");
options.AddArgument("ignore-certificate-errors");
options.AddArgument("--disable-popup-blocking");
options.AddArgument("--disable-gpu");
options.AddArgument("--incognito");
options.AddUserProfilePreference("disable-popup-blocking", "true");
driveri = new ChromeDriver(options);
driveri.Navigate().GoToUrl("http://web.com"); IJavaScriptExecutor js = (IJavaScriptExecutor)driveri;
js.ExecuteScript("window.alert = function() {};");
}

显示等待50秒

WebElement ele_14 = (new WebDriverWait(webDriver, 50)).until(ExpectedConditions.elementToBeClickable(By.xpath(SIT_Objects.tab_MPF)));
//visibilityOfElementLocated
    public boolean isPresent(String xpath, int waitingTimeInSec) {
try {
WebDriverWait wait = new WebDriverWait(webDriver, waitingTimeInSec);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(xpath)));
} catch (TimeoutException e) {
return false;
}
return true;
}

隐式等待

driver.manage().timeouts().implicitlyWait(50,TimeUnit.SECONDS); //与显式等待同时存在时,以其中最大值为准。

js

driver = new ChromeDriver(options);
Javascript = ((JavascriptExecutor) driver);
boolean jsReady=(Boolean)Javascript.executeScript("return document.readyState").toString().equals("complete");
while(!jsReady){
Thread.sleep(100);
}
//Wait for jQuery to load
{
ExpectedCondition<Boolean> jQueryLoad = driver -> ((Long) ((JavascriptExecutor) driver).executeScript("return jQuery.active") == 0);
boolean jqueryReady = (Boolean) js.executeScript("return jQuery.active==0");
if (!jqueryReady) {
//System.out.println("JQuery is NOT Ready!");
wait.until(jQueryLoad);
}
wait.until(jQueryLoad);
}
//Wait for ANGULAR to load
{
String angularReadyScript = "return angular.element(document).injector().get('$http').pendingRequests.length === 0";
ExpectedCondition<Boolean> angularLoad = driver -> Boolean.valueOf(((JavascriptExecutor) driver).executeScript(angularReadyScript).toString());
boolean angularReady = Boolean.valueOf(js.executeScript(angularReadyScript).toString());
if (!angularReady) {
//System.out.println("ANGULAR is NOT Ready!");
wait.until(angularLoad);
}
}
//Wait for Javascript to load
{
ExpectedCondition<Boolean> jsLoad = driver -> ((JavascriptExecutor) driver).executeScript("return document.readyState").toString()
.equals("complete");
boolean jsReady = (Boolean) js.executeScript("return document.readyState").toString().equals("complete");
//Wait Javascript until it is Ready!
if (!jsReady) {
//System.out.println("JS in NOT Ready!");
wait.until(jsLoad);
}
}

刷新

driver.navigate().refresh();

代理

Proxy proxy = new Proxy();
proxy.setNoProxy("connections.manulife.com;intranet01.manulife.com;ifshome.manulife.com;adfs.man;ulife.com;sts.manulife.com;ctx.manulife.com;mlilapp00.manulife.com;*.manulife.;net;centralsharepoint;205.*.*.*;209.*.*.*;192.168.*.*;10.*.*.*;*.phbdomain.loc;al;*.manulifeusa.com;ato.manulife.com;hkitsp.ap.manulife.com;connections.manul;ife.com;ars7.manulife.com;*.ap.manulife.com;globalgrc.manulife.com;*.mfcgd.com;*.pcf.manulife.com;*.gsdcf.manulife.com;giam.manulife.com;*.mbpscd.com;*.plat;form.manulife.io;*.manulife.io;Ifsgl.manulife.com;*.mbpscd.com;join.poolweb.ma;nulife.com;20.139.52.44;*.japan.corp.manulife.com;*.mliph.manulife.com;*.mliph.manulife.com.ph;set4success.manulife.com;digipasshk.manulife.com;digipasskl.manulife.com;citrixstore.jhancock.com;mywcasd01.dc1.manulife.net.my");
options.setProxy(proxy);

Refer

https://cloud.tencent.com/developer/article/1497428

selenium_java的更多相关文章

  1. Selenium_Java版本安装及初试

    [环境] ①JDK版本:jdk1.8.0_73 ②Eclipse:jee-mars-4.5.2 ③Selenium:selenium-java-3.5.3 ④GoogleChrome:60 ⑤chro ...

  2. Selenium_java coding

    1)public class HelloWorld { // class 是类的意思 // 类名指的是class后面这个词,这个词是我们起的名 public static void main(Stri ...

  3. 【自动化学习笔记】_环境搭建Selenium2+Eclipse+Java+TestNG_(一)

    目录 第一步  安装JDK 第二步 下载Eclipse 第三步 在Eclipse中安装TestNG 第四步 下载Selenium IDE.SeleniumRC.IEDriverServer 第五步 下 ...

  4. JDK eclipse selenium 安装以及环境变量的配置

    原文地址https://www.cnblogs.com/zmhsoup/p/5249663.html [自动化学习笔记]_环境搭建Selenium2+Eclipse+Java+TestNG_(一) 目 ...

  5. selenium学习网址

    1.http://www.testclass.net/selenium_java/#      testclass网址 2.http://www.yiibai.com/selenium/seleniu ...

  6. 环境搭建Selenium2+Eclipse+Java+TestNG_(一)

    第一步  安装JDK 第二步 下载Eclipse 第三步 在Eclipse中安装TestNG 第四步 下载Selenium IDE.SeleniumRC.IEDriverServer 第五步 下载Fi ...

  7. java selenium 自动化笔记-不是0基础,至少有java基础

    本来今天要学GitHub的,但是在群里问了下小伙伴时被暴击.说我学的东西太多太杂,不是很深入,都是皮毛.哎~自己早深有意识到,因个人能力吧,找的资料都不是很全,加上实际工作没有应用到.所以写一篇sel ...

  8. selenium基于java 一 软件安装

    学习网站 http://www.testclass.net/selenium_java/ 一·安装java环境及eclipse,网上教程较多不讲 二·下载火狐浏览器(旧版) 下载地址:链接: http ...

  9. java中selenium判断某个元素是否存在

    selenium工具 直接通过findElement方法获取某个元素,如果该元素不存在肯定会报错,selenium又没有可以判断该元素是否存在的方法 于是我们可以手写一个工具类,来判断这个元素是否存在 ...

随机推荐

  1. idea 党用快捷键

    实用快捷键: Ctrl+/ 或 Ctrl+Shift+/ 注释(// 或者/*...*/ )Ctrl+D 复制行Ctrl+X 删除行快速修复 alt+enter (modify/cast)代码提示 a ...

  2. c++11 移动语义move semantics

    performance, expensive object copies move semantics, temporary objects implemented with rvalue refer ...

  3. 08-【jsp重点】

    jsp的四个作用域和9个内置对象 jsp内置对象[重点]:pageContext.request.session.application.response.out.page.exception.con ...

  4. 03:Java基础语法(二)

    Java基础语法 Java运算符 算术运算符 运算符是一种特殊的符号,用以表示数据的运算.赋值和比较等.1.操作数:参与运算的数据 称为操作数.2.表达式:运算符和操作数的整体 称为表达式.单独的一个 ...

  5. 2019-2020-1 20199319《Linux内核原理与分析》第一周作业

    一.Linux系统简介 通过实验一了解了Linux 的历史,Linux与windows之间的区别以及学习Linux的方法.因为一直用的都是windows系统,习惯了图形界面,而Linux是通过输入命令 ...

  6. redis 的启动、关闭 判断其是否在运行中

    #检查后台进程是否正在运行 ps -ef |grep redis ps aux | grep redis #检测6379端口是否在监听 netstat -lntp | grep 6379 #使用配置文 ...

  7. PHP程序员要掌握的技能

    1. Composer 第一点就要提 Composer ,自从 Composer 出现后,PHP 的依赖管理可以变得非常简单.程序内依赖一些类库和框架,直接使用 Composer 引入即可,通过使用 ...

  8. go学习开篇

            我是做java开发的,从接触java开始算,已经8年了,为什么会想到学go语言呢?前端时间我一直在学习jvm,java的一些更底层的东西,梳理回顾时,感觉可以通过学习其他开发语言,来提 ...

  9. https加载http资源,导致ios手机上的浏览器图片加载问题

    今天解决一个线上bug的时候发现的问题,如下图: 从表象来看,同样的图片,安卓手机上可以正常展示,但是到ios手机上首次进入页面就不能正常显示图片,必须手动刷新一次页面才能正常加载. 这时候,我们首先 ...

  10. (一)数据库系统概述和ER图

    1.数据库系统 数据库系统有数据库.数据库管理系统.应用系统和数据库管理员组成.数据库呢就是数据的集合,应用系统和管理员就不说了,数据库管理系统即常说的DBMS,比如我们用的mysql,oracle, ...