设置驱动的方法(Chrome 亲测ok)
驱动下载地址 http://selenium-release.storage.googleapis.com/index.html
package com.selenium.java.webdriver2testng;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.Platform;
import org.openqa.selenium.Point;
import org.openqa.selenium.Rectangle;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class OpenDriverDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver;
String baseurl = "https://www.baidu.com";
// DesiredCapabilities类实现分布式指定执行自动化测试环境
DesiredCapabilities caps = DesiredCapabilities.chrome();
// 设置使用的浏览器名称
caps.setBrowserName("chrome");
caps.setPlatform(Platform.WINDOWS);
System.setProperty("webdriver.chrome.driver",
"drivers/chromedriver.exe");
driver = new ChromeDriver();
// Firefox浏览器安装位置最好默认,不然就需要指定浏览器路径,浏览器调用不起来,的原因注意查看日志,从驱动版本和浏览器的版本兼容查起
// System.setProperty("webdriver.firefox.bin","D:\\Program Files (x86)\\Tencent\\Mozilla Firefox\\firefox.exe");
// System.setProperty("webdriver.gecko.driver",
// "drivers/geckodriver64.exe");
// driver=new FirefoxDriver();
// 设置浏览器的属性,key,value,对应里面的值,驱动路径可以是相对路径
// System.setProperty("webdriver.ie.driver",
// "drivers/IEDriverServer.exe");
// 创建一个浏览器驱动实例
// driver = new InternetExplorerDriver();
// 实例即对象,调用浏览器驱动封装好的方法,get()打开网址,里面是一个字符串url,同时打开浏览器的方法还有navigate().to()
// driver.get("https://www.baidu.com");
driver.navigate().to(baseurl);
// 窗口最大化
driver.manage().window().maximize();
// 设置隐私等待时间,
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
System.out.println("获取当前窗口的title:" + driver.getTitle());// 返回的是一个字符串类型
// 操作一下输入框,点击查询selenium的内容
driver.findElement(By.id("kw")).sendKeys("selenium");
driver.findElement(By.id("su")).click();
// 用例执行完,关闭浏览器,这个是关闭当前,如果只有一个就是所有。quit()是关闭退出所有关联的窗口
driver.close();
}
}
原文链接:https://blog.csdn.net/u011466469/article/details/88858093
设置驱动的方法(Chrome 亲测ok)的更多相关文章
- table的td设置1px的方法,亲测有效
第一种方法: 1.将table的属性设置为:BORDER=0 .cellspacing=1 : 2.设置table的背景色为即你要设置的table的边框颜色: 3.设置所有td背景色为#ffffff白 ...
- MyEclipse 2017 ci6 安装反编译插件(本人自己摸索的方法,亲测可行)
注: 本文来源于:Smile_Miracle 的< MyEclipse 2017 ci6 安装反编译插件(本人自己摸索的方法,亲测可行) > 第一步:关闭ME,去一下地址下载jad的反编译 ...
- C#.NET中对称和非对称加密、解密方法汇总--亲测可用
C#.NET中对称和非对称加密.解密方法汇总--亲测可用 在安全性要求比较高的系统中都会涉及到数据的加密.解密..NET为我们封装了常用的加密算法,例如:MD5,DES,RSA等.有可逆加密,也有 ...
- R语言—如何安装Github包的解决方法,亲测有效
R语言—如何安装Github包的解决方法,亲测有效 准备安装材料: R包-REmap GitHub下载地址:https://github.com/lchiffon/REmap R包-baidumap ...
- django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.2的最佳处理方法,亲测可用
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.2 ...
- Win10微软帐户切换不回Administrator本地帐户的解决方法【亲测】
在Win10系统中经常会用到微软帐户登录,如应用商店等地方,不过一些用户反馈原来使用Administrator帐户被绑定微软帐户后无法切换回本地帐户,连[改用本地帐户登录]按钮都没有,那么怎么解决呢? ...
- myeclipse 9.0 破解方法,亲测可用
MyEclipse 9.0的破解方法,步骤如下: 1.破解公钥,确保MyEclipse没有开启,否则失败! 用WinRAR打开Common\plugins\com.genuitec.eclipse.c ...
- Windows10安装pycocotools方法,亲测可用!
如果遇到:No module named 'pycocotools' 错误,说明你的环境需要安装pycocotools,以下介绍在Windows10下安装pycocotools的方法,这是本人结合看过 ...
- CSS响应式:根据分辨率加载不同CSS的几个方法,亲测可用
有时候你需要把同一个页面在手机和pc同时打开,其中有一个办法就是判断不同分辨路加载不同的css 小编总结了几种分别加载css的方法: 1.比较复杂的使用js判断加载不同css (亲测可用) 但是这种方 ...
随机推荐
- Codeforces A. Kyoya and Colored Balls(分步组合)
题目描述: Kyoya and Colored Balls time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- python正则表达式(4)--search方法
1.re.search函数 re.search 扫描整个字符串并返回第一个成功的匹配,如果匹配失败search()就返回None. (1)函数语法: re.search(pattern, string ...
- 2019牛客暑期多校训练营(第五场)B:generator 1 (10进制快速幂)
题意:给定x0,x1,a,b,满足xi=a*xi-1+b*xi-2: 求xn,n<10^(10^6): 思路:10进制快速幂裸题.降幂来写好像也是可以的,但是循环节不是phi(mod),所以数学 ...
- swift是面向对象、面向协议、高阶类型、灵活扩展、函数式编程语言
swift是面向对象.面向协议.高阶类型.灵活扩展.函数式编程语言
- python - django 将图片路径地址转换成 InMemoryUploadedFile 并存储数据库
# 问题场景:对接第三方时遇到一个图片存储问题,对方给的是他们服务器的图片路径地址,但是 我这里存储图片用的是 ImageField 字段属性,也设置了存储路径,现在一旦将图片显示到前端就会将设置的 ...
- 【JVM】内存和SWAP问题
一.现象 1.系统稳定运行,偶尔发生响应超时的情况.查看下游依赖服务和数据库状态都良好.超时完全是由于服务本身问题造成的.重启不能解决问题,一直会间隔性的发生超时 二.原因分析 第一种情况,系统内存够 ...
- [Algorithm] 122. Best Time to Buy and Sell Stock II
Previous one: https://www.cnblogs.com/Answer1215/p/11974453.html Say you have an array for which the ...
- ABP 02 解决 界面为英文
原文:https://www.cnblogs.com/wswind/p/10313968.html 1.直接改数据库 2.在数据迁移前,更改默认值 注意: 我的项目已经初始化了,数据库已经都生成好了, ...
- bzoj 1260涂色 题解
题面 区间dp, 我学的也不怎么好. myj说动态规划就是搜索的无限剪枝. 所以是搜了网上的代码, 看了看. 思路就是枚举区间,f数组就是存储从i到j需要的最少次数, 当然一开始他们的值要先设置一个很 ...
- luogu P1447 [NOI2010]能量采集 欧拉反演
题面 题目要我们求的东西可以化为: \[\sum_{i=1}^{n}\sum_{j=1}^{m}2*gcd(i,j)-1\] \[-nm+2\sum_{i=1}^{n}\sum_{j=1}^{m}gc ...