设置驱动的方法(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 (亲测可用) 但是这种方 ...
随机推荐
- python __getattr__ & __getattribute__ 学习
实例属性的获取和拦截, 仅对实例属性(instance, variable)有效, 非类属性 getattr: 适用于未定义的属性, 即该属性在实例中以及对应的类的基类以及祖先类中都不存在 1. 动态 ...
- VS创建C工程
打开VS编辑器: 填写项目名称,控制项目位置,创建: 在源文件中添加新项: 填写文件名称,修改后缀: 编写一个简单的hello word编译看看windows环境支持如何:
- first集合follow集的求法
FIRST集的定义 : 设G=(VT,VN,P,S)是上下文无关文法 FIRST(a)={a|a=>*ab,a∈VT, a,b∈V*} 若a=>*ε则规定ε∈FIRST (a) FIRST ...
- input事件在进行模糊搜索时,用到的即时监测input的值变化的方法(即时搜索的input和propertychange方法)
做搜索功能的时候,经常遇到输入框检查的需求,最常见的是即时搜索,今天好好小结一下. 即时搜索的方案: (1)change事件 触发事件必须满足两个条件: a)当前对象属性改变,并且是由键盘或鼠标 ...
- Caused by: java.lang.IllegalStateException: duplicate key: datasource
java.lang.IllegalStateException: Failed to load property source from location 'classpath:/applicatio ...
- css 宽高等比
1.利用js 2.容器里添加图片,让图片的等比缩放撑大容器,图片z-index=负数,
- 20180414模拟赛T1——BEAD
BEAD 源程序名 BEAD.???(PAS,C,CPP) 可执行文件名 BEAD.EXE 输入文件名 BEAD.IN 输出文件名 BEAD.OUT 时间限制 1S 内存限制 128MB 有n颗形状和 ...
- 【Postgres】根据字段数据创建空间字段
--添加空间字段 , ); --根据其他字段更新空间字段数据 update "GIS" b ) from "GIS" a where b."ID&qu ...
- secureCRT无操作自动登出时间修改(亲测可用)
转自:http://blog.sina.com.cn/s/blog_6bcf42010102vlt9.html secureCRT连接机器经常会因为一段时间无操作就退出了,提示timed out wa ...
- Is Safari on iOS 6 caching $.ajax results? post Cache
https://stackoverflow.com/questions/12506897/is-safari-on-ios-6-caching-ajax-results Since the upgra ...