驱动下载地址 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)的更多相关文章

  1. table的td设置1px的方法,亲测有效

    第一种方法: 1.将table的属性设置为:BORDER=0 .cellspacing=1 : 2.设置table的背景色为即你要设置的table的边框颜色: 3.设置所有td背景色为#ffffff白 ...

  2. MyEclipse 2017 ci6 安装反编译插件(本人自己摸索的方法,亲测可行)

    注: 本文来源于:Smile_Miracle 的< MyEclipse 2017 ci6 安装反编译插件(本人自己摸索的方法,亲测可行) > 第一步:关闭ME,去一下地址下载jad的反编译 ...

  3. C#.NET中对称和非对称加密、解密方法汇总--亲测可用

    C#.NET中对称和非对称加密.解密方法汇总--亲测可用   在安全性要求比较高的系统中都会涉及到数据的加密.解密..NET为我们封装了常用的加密算法,例如:MD5,DES,RSA等.有可逆加密,也有 ...

  4. R语言—如何安装Github包的解决方法,亲测有效

    R语言—如何安装Github包的解决方法,亲测有效 准备安装材料: R包-REmap GitHub下载地址:https://github.com/lchiffon/REmap R包-baidumap ...

  5. 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 ...

  6. Win10微软帐户切换不回Administrator本地帐户的解决方法【亲测】

    在Win10系统中经常会用到微软帐户登录,如应用商店等地方,不过一些用户反馈原来使用Administrator帐户被绑定微软帐户后无法切换回本地帐户,连[改用本地帐户登录]按钮都没有,那么怎么解决呢? ...

  7. myeclipse 9.0 破解方法,亲测可用

    MyEclipse 9.0的破解方法,步骤如下: 1.破解公钥,确保MyEclipse没有开启,否则失败! 用WinRAR打开Common\plugins\com.genuitec.eclipse.c ...

  8. Windows10安装pycocotools方法,亲测可用!

    如果遇到:No module named 'pycocotools' 错误,说明你的环境需要安装pycocotools,以下介绍在Windows10下安装pycocotools的方法,这是本人结合看过 ...

  9. CSS响应式:根据分辨率加载不同CSS的几个方法,亲测可用

    有时候你需要把同一个页面在手机和pc同时打开,其中有一个办法就是判断不同分辨路加载不同的css 小编总结了几种分别加载css的方法: 1.比较复杂的使用js判断加载不同css (亲测可用) 但是这种方 ...

随机推荐

  1. Spring Cloud注册中心Eureka设置访问权限并自定义鉴权页面

    原文:https://blog.csdn.net/a823007573/article/details/88971496 使用Spring Security实现鉴权 1. 导入Spring Secur ...

  2. SpringCloud2.0 Eureka Client 服务注册 基础教程(三)

    1.创建[服务提供者],即 Eureka Client 1.1.新建 Spring Boot 工程,工程名称:springcloud-eureka-client 1.2.工程 pom.xml 文件添加 ...

  3. pandas知识点脑图汇总

    参考文献: [1]Pandas知识点脑图汇总

  4. Selenium_webdriver+java+TestNG入门UI自动化

    web ui自动化测试需要的工作:Eclipse(JAVA编译器).selenium(库文件).webdriver(浏览器驱动).testng的lib; 如图: 第一步:先部署坏境,下载seleniu ...

  5. 字符流,字节流,属性集(Properties)

    字节输入流(InputStream) java.io.InputStream抽象类是表示字节输入流的所有类的超类.可以读取字节信息到内存中.它定义了字节输入流的基本共性功能方法. public voi ...

  6. python爬虫中遇到的问题以及解决方法

    (1)运行后报错:“TypeError: cannot use a string pattern on a bytes-like” 原因:content用decode(‘utf-8’)进行解码,由by ...

  7. git 学习笔记 —— 保留/丢弃当前分支修改并切换至其他分支

    笔者在本地终端进行 git 工作目录的相关处理时,遇到由于某种情况需要使用 git checkout 命令切换到其他分支的情景.此时,若已经对当前分支做了一定的修改,则直接切换分支时 git 会提示错 ...

  8. Dockerfile 常见指令的意义/常见的使用方式/使用示例/

    一.什么是 Dockerfile ? Dockerfile 就是生成docker镜像的指令集, 通过使用docker工具执行这些指令集可以方便快捷地生成镜像, 并且能不断复用 Dockerfile 指 ...

  9. springboot集成mail实现邮件服务

    1,新建mailconfig类,对邮件服务固定配置进行实体封装: import java.util.Properties; import org.springframework.beans.facto ...

  10. js版本规范的表示:ES6 == ES 6 == ECMAScript 6 == ECMA-262 6

    Ecma 国际大会宣布正式批准ECMA-262第 6 版,亦即 ECMAScript 2015(曾用名:ECMAScript 6.ES6)的语言规范. 关系 ECMA-262 == ECMAScrip ...