Chrome browser implements the WebDriver protocol by using an executable file called ChromeDriver.exe. This executable file starts a server on your system and all your tests will communicate to this server in order to run your tests.

Chrome浏览器通过使用名为ChromeDriver.exe的可执行文件来实现WebDriver协议 该可执行文件将启动系统上的服务器,并且所有测试都将与该服务器通信,以便运行测试。

In this article, we will learn

在本文中,我们将学习

  • How to download the latest version of Selenium ChromeDriver如何下载最新版本的Selenium ChromeDriver
  • How to setup Selenium ChromeDriver in multiple ways如何以多种方式设置Selenium ChromeDriver
  • 下载Selenium ChromeDriver (Download Selenium ChromeDriver)

    First, we have to download the latest version of ChromeDriver, mainly because it supports the latest versions of Chrome, and it contains all the bug fixes. The following are the steps to download ChromeDriver.

    首先,我们必须下载最新版本的ChromeDriver ,主要是因为它支持最新版本的Chrome,并且包含所有错误修复。 以下是下载ChromeDriver的步骤。

  • Step 1: Go to the Chromium official website and download latest version of ChromeDriver based on your operating system第1步 : 访问Chromium官方网站并根据您的操作系统下载最新版本的ChromeDriver
  • Chrome Version

    Chrome版本

  • Step 2: Click on ChromeDriver 73.0.3683.20 link. You will be navigated to ChromeDriver download page which contains ChromeDriver for Linux, Mac and Windows operating systems.第2步 :点击ChromeDriver 73.0.3683.20链接。 您将被导航到ChromeDriver下载页面,其中包含适用于Linux,Mac和Windows操作系统的ChromeDriver。
  • Note: Here we are working on Windows Operating system, we need to download the corresponding Chrome driver of Windows version. If your Operating System is Linux or Mac then you need to download the corresponding Chrome driver.

    注意:在这里我们正在Windows操作系统上工作,我们需要下载相应的Windows版本的Chrome驱动程序。 如果您的操作系统是Linux或Mac,则需要下载相应的Chrome驱动程序。

    Chrome Index

    Chrome指数

  • Step 3: Click on chromedriver_win32.zip to download ChromeDriver for Windows.步骤3 :点击chromedriver_win32.zip下载适用于Windows的ChromeDriver。
  • Step 4: Once the zip file is downloaded, you can unzip it to retrieve chromedriver.exe. Note the location where you extracted the ChromeDriver. Location will be later used to instantiate the driver.步骤4 :下载zip文件后,您可以将其解压缩以检索chromedriver.exe。 请注意您提取ChromeDriver的位置。 位置将在以后用于实例化驱动程序。
  • Chrome Driver

    Chrome驱动

    使用Selenium WebDriver启动Chrome浏览器 (Launching Chrome Browser using Selenium WebDriver)

    Launching a Chrome driver is easy for launching as any other driver.
    WebDriver = new ChromeDriver();

    与其他任何驱动程序一样,启动Chrome驱动程序很容易。
    WebDriver =新的ChromeDriver();

    package com.journaldev.selenium.Chrome;import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;public class ChromeDriver {public static void main(String[] args) {WebDriver driver= new ChromeDriver();driver.get("https://journaldev.com");}
    } 

    When you run above program we get an exception called java.lang.IllegalStateException. which tells The path to the driver executable must be set by webdriver.chrome.driver.

    当您在上述程序上运行时,我们将得到一个名为java.lang.IllegalStateException的异常 告诉驱动程序可执行文件的路径必须由webdriver.chrome.driver设置。

    To overcome the above problem we need to download the ChromeDriver in order to work with selenium commands which we are writing on Chrome. Every browser as a driver. The driver for Chrome is the ChromeDriver. The selenium commands will be interpreted by ChromeDriver and it will be executed on Chrome.

    为了解决上述问题,我们需要下载ChromeDriver才能使用我们在Chrome上编写的Selenium命令。 每个浏览器都作为驱动程序。 Chrome的驱动程序是ChromeDriver。 Selenium命令将由ChromeDriver解释,并将在Chrome上执行。

    初始化ChromeDriver的不同方法 (Different ways to initialize ChromeDriver)

    There are 2 methods to initialize ChromeDriver

    有两种方法可以初始化ChromeDriver

  • Use Webdriver.Chrome.Driver使用Webdriver.Chrome.Driver
  • Use Environment Variables使用环境变量
  • 方法1:使用Webdriver.chrome.driver系统属性 (Method 1: Use Webdriver.chrome.driver system property)

    Code to set the System properties is

    设置系统属性的代码是

    System.setProperty(“webdriver.chrome.driver”,“Path to chromedriver.exe”);

    The complete program to launch the ChromeDriver will be like this:

    启动ChromeDriver的完整程序如下所示:

    package com.journaldev.selenium.Chrome;import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;public class ChromeDriver {public static void main(String[] args) {System.setProperty("webdriver.chrome.driver","D:\\Drivers\\chromedriver.exe");WebDriver driver= new ChromeDriver();driver.get("https://journaldev.com");String PageTitle = driver.getTitle();System.out.println("Page Title is:" + PageTitle);driver.close();}
    } 

    When you run the above program you will notice that Journaldev.com is opened in the new Chrome window and it will print the website title in the console.

    当您运行上述程序时,您会发现在新的Chrome窗口中打开Journaldev.com,它将在控制台中打印网站标题。

    方法2:在Windows环境变量中设置ChromeDriver路径 (Method 2: Setting ChromeDriver Path in Windows Environment Variables)

  • Step 1: Go to My Computer and Right click to get the context menu.步骤1 :转到我的电脑,然后右键单击以获取上下文菜单。
  • MyComputer Properties

    MyComputer属性

  • Step 2: Click on the Change Setting on the opened window.步骤2 :在打开的窗口中单击“ 更改设置 ”。
  • Change Settings

    更改设置

  • Step 3: Click on Advance tab and click on Environment Variables.步骤3 :单击高级选项卡,然后单击环境变量。
  • System Properties

    系统属性

  • Step 4: Select Path under System Variables and click on Edit.步骤4 :在System Variables系统变量)下选择Path(路径) ,然后单击Edit(编辑)。
  • Environment Variables

    环境变量

  • Step 5: At the end of the string use semicolon and paste the path of the ChromeDriver. On my machine my ChromeDriver exe resides in D:\Drivers\步骤5 :在字符串的末尾使用分号并粘贴ChromeDriver的路径 在我的计算机上,我的ChromeDriver exe驻留在D:\ Drivers \
  • Path

    路径

    Note: Once the path is set you would not need to set the System property every time in the script. Your script will work without the System Property code.

    注意:设置路径后,您无需每次在脚本中都设置System属性。 您的脚本无需系统属性代码即可工作。

    The complete program to launch the ChromeDriver will be like this:

    启动ChromeDriver的完整程序如下所示:

    
    package com.journaldev.selenium.Chrome;import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromefoxDriver;public class ChromeDriver {public static void main(String[] args) {WebDriver driver = new ChromeDriver();driver.get("https://journaldev.com");String PageTitle = driver.getTitle();System.out.println("Page Title is:" + PageTitle);driver.close();}}
    

    When you run the above program your script will work without the System Property code and you will notice that Journaldev.com is opened in the new Chrome window and it will print the website title in the console.

    当您运行上述程序时,脚本将在没有系统属性代码的情况下运行,并且您会注意到在新的Chrome窗口中打开了Journaldev.com,并将在控制台中打印网站标题。

    翻译自: https://www.journaldev.com/26616/running-test-on-selenium-chrome-driver

在Selenium Chrome驱动程序上运行测试相关推荐

  1. selenium火狐驱动_在Selenium Firefox驱动程序上运行测试

    selenium火狐驱动 带有Selenium 3.0的Gecko Marionette Firefox驱动程序 (Gecko Marionette Firefox Driver with Selen ...

  2. [Selenium] 如何在老版本的Chrome 浏览器上使用selenium

    由于Chrome Driver 只兼容Chrome  浏览器12.0.712.0 和之后的新版本,会因此如果要在老版本的Chrome  浏览器上使用Selenium, 则只能使用 SeleniumRC ...

  3. Linux服务器上搭建Python+Selenium+Chrome的运行环境(静默模式、无图形)

    本文是<统计CSDN博客的访问量>的部署篇,为了持续统计CSDN的访问量.并进行分析,因此需要在Linux上搭建Selenium + Chrome driver的运行环境 安装Seleni ...

  4. chrome java mac下载_Mac上Java+selenium+Chrome环境配置

    前言 本人之前在window下使用Java+selenium+Firefox进行UI测试,由于window本子集显烧了更换了MacBook Pro,所以开始研究如何在Mac环境下进行UI自动化测试.但 ...

  5. python+selenium+chrome实现淘宝购物车秒杀自动结算

    python+selenium+chrome实现淘宝购物车秒杀自动结算 一.所需环境 二.安装 三.代码 最后run()一把就ok了!! 之前总是想要买aj,但是淘宝店铺每次发售手动抢的时候一般都会被 ...

  6. Ubuntu 无界面使用selenium chrome + headless

    Ubuntu 无界面使用selenium chrome + headless 1. 安装 selenium : sudo pip install selenium 2. 安装 chromdriver: ...

  7. windows10 Selenium Chrome 驱动安装

    windows10 Selenium Chrome 驱动安装 确定chrome浏览器版本 右键上角按钮 --> 帮助 --> 关于Google Chrome(G) 打开网址 https:/ ...

  8. Python + Selenium + Chrome 使用代理 auth 的用户名密码授权

    2019独角兽企业重金招聘Python工程师标准>>> 米扑代理,全球领导的代理品牌,专注代理行业近十年,提供开放.私密.独享代理,并可免费试用 米扑代理官网:https://pro ...

  9. python3 + selenium + (chrome and firefox)使用

    目录 瞎扯一句 简介 最后放模板 瞎扯一句 最近在做一个关于 selenium 相关的项目,在选择浏览器方面,一般有3种方案: chrome phantomJs firefox(推荐) 网上有很多教程 ...

最新文章

  1. jqgrid如何渲染表格数据_jqgrid,jquery_jqGrid pivot 增加分项小计,jqgrid,jquery,jquery插件,javascript,表格 - phpStudy...
  2. Pandas中Apply函数加速百倍的技巧
  3. javascript常用方法函数收集
  4. Redis学习(3)-redis启动
  5. 深入学习python内存管理
  6. ubuntu20.04安装mysql教程
  7. [Python学习记录]——Hello Python
  8. linux安装meb工具,linux-docker下安装禅道全部
  9. php的memcache安装,在window10下面
  10. 我的程序跑了 60 多小时,就是为了让你看一眼 JDK 的 BUG 导致的内存泄漏
  11. vue验证整数_前端Vue中常用rules校验规则
  12. Eclipse运行程序报错: Errors running builder ‘Integrated External Tool Builder‘ on project
  13. 英特尔再爆重大芯片漏洞,苹果谷歌微软相继中招!
  14. Informatica通过人工智能重新定义数据管理助力数据驱动型数字化转型
  15. python 爬虫 客户端_python爬虫
  16. CSS基础(挺详细版)
  17. 从wireshark 抓包中的导出 H.264 变成可用暴风直接播放的H264 裸码流文件
  18. c# 超时时间已到.在操作完成之前超时时间已过或服务器未响应,超时过期了。在操作完成或服务器没有响应之前经过的超时时间。声明已被终止...
  19. 央行最新公布2019支付牌照持牌机构公司列表,共255家(附清单)
  20. Java面试快问快答-Instrument机制

热门文章

  1. 图象和文本的绝对位置(九)
  2. .eslintrc.js相关配置
  3. delphi常用函数大全(转)
  4. Java配置环境变量、方法和原因
  5. 浅谈 Redis 与 MySQL 的耦合性以及利用管道完成 MySQL 到 Redis 的高效迁移
  6. JavaScript 弹出层,背景变暗
  7. Keil5 MDK版 下载与安装教程(STM32单片机编程软件)
  8. stl之list双向链表容器应用基础
  9. 华为在鸿蒙的另一张王牌,华为的这两张王牌,将助力Mate40系列角逐安卓机皇的位置...
  10. 安装kepserver找不到根证书_考完二手车评估师证书却找不到工作,面试官的话让我记忆犹新!...