设置驱动的方法(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 (亲测可用) 但是这种方 ...
随机推荐
- 用JAVA实现找出输入字符串中的出现次数最多的字符及其次数;
//通过Map 类实现,通过键值对的方式,可以将输入的字符串的每一个字符,作为键,每个字符出现的次数作为值:如下: public class Find { public static void mai ...
- 23、matplotlib数据可视化、绘图库模块
matplotlib官方文档:https://matplotlib.org/contents.html?v=20190307135750 matplotlib是一个绘图库,它可以创建常用的统计图,包括 ...
- hiveserver2和zookeeper的HA搭建(转)
最近公司新项目申请资源,虚拟机资源打开时候使用source login.sh的脚本来进行登录注册,好奇心驱使下看了看里面的shell脚本,使用到了hiveserver2的zookeeper连接,百度一 ...
- keywordAsVar.php
<?php //keywordAsVar.php #keywordAsVar.php $True="我是变量True"; echo($True); echo("&l ...
- PHP函数file_get_contents()使用 https 协议时报错:SSL operation failed
场景: file_get_contents() 函数是用于将文件的内容读入到一个字符串中,是读取文件内容常用的函数之一. 但是有时在服务器上使用file_get_contents() 函数请求http ...
- BZOJ 4411: [Usaco2016 Feb]Load balancing 线段树+二分
code: #include <bits/stdc++.h> #define N 100060 #define M 1000000 #define lson x<<1 #def ...
- SOS从内存转储中提取模块(EXE、DLL和其他二进制文件)
假设有一种情况,您从客户那里得到一个内存转储,需要模块(DLL.EXE.OCX等)来进一步调试..(.NET模块可用于通过反向工程查看源代码.)我们可以使用windbg目录中的clr10\sos.dl ...
- ent 基本使用十五 一个图遍历的例子
以下是来自官方的一个user group pet 的查询demo 参考关系图 环境准备 docker-compose mysql 环境 version: "3" services: ...
- CGLIB和Java动态代理的区别(笔记)
java常用知识点: 1.Java动态代理只能够对接口进行代理,不能对普通的类进行代理(因为所有生成的代理类的父类为Proxy,Java类继承机制不允许多重继承):CGLIB能够代理普通类:2.Jav ...
- Numpy中数据的常用的保存与读取方法
小书匠 深度学习 文章目录: 1.保存为二进制文件(.npy/.npz) numpy.save numpy.savez numpy.savez_compressed 2.保存到文本文件 numpy. ...