selenium火狐驱动

带有Selenium 3.0的Gecko Marionette Firefox驱动程序 (Gecko Marionette Firefox Driver with Selenium 3.0)

Many of you know that before Selenium 3, Mozilla Firefox browser was the default browser for Selenium where we launch Firefox by default without any property settings. After Selenium 3.0 has been released in the market and in this version of Selenium, testers need to initialize the script to use Firefox using GeckoDriver explicitly.

你们中的许多人都知道,在Selenium 3之前,Mozilla Firefox浏览器是Selenium的默认浏览器,在默认情况下,我们在没有任何属性设置的情况下启动Firefox。 在市场上以及此版本的Selenium中发布Selenium 3.0之后,测试人员需要使用GeckoDriver显式初始化脚本以使用Firefox。

什么是壁虎? (What is Gecko?)

Gecko is a web browser engine which is developed by Mozilla Foundation and written in C++. It is an Open Source. Web browser engine is a software program that is used to control and render the content (like HTML, CSS, XML, images) on the browser.

Gecko是由Mozilla Foundation开发并用C ++编写的Web浏览器引擎 。 它是一个开源的。 Web浏览器引擎是一种软件程序,用于控制和呈现浏览器上的内容(如HTML,CSS,XML,图像)。

什么是壁虎驱动程序? (What is Gecko Driver?)

Gecko is a Web Browser engine used in various applications developed by Mozilla Foundation and the Mozilla Corporation. It is a proxy which is used to interact with the browsers that run on Gecko-based browsers like Firefox. Gecko driver is the link between your tests in Selenium WebDriver and Mozilla Firefox browser. As Selenium 3.0 will not have any native implementation of Firefox, we need to direct all the driver commands through Gecko Driver. Gecko Driver is an executable file that you need to have in one of the system paths before running your tests.
The Firefox browser implements the WebDriver protocol using an executable called GeckoDriver.exe. Selenium uses WebDriver protocol to send requests to GeckoDriver, which translates calls into the Marionette automation protocol and Firefox will understand the commands transmitted in the form of Marionette protocol and executes them.

Gecko是Web浏览器引擎,可用于Mozilla Foundation和Mozilla Corporation开发的各种应用程序。 它是一个代理,用于与在基于Gecko的浏览器(如Firefox)上运行的浏览器进行交互。 Gecko驱动程序是Selenium WebDriver和Mozilla Firefox浏览器之间的测试之间的链接。 由于Selenium 3.0将不具有Firefox的任何本机实现,因此我们需要通过Gecko Driver定向所有驱动程序命令。 Gecko驱动程序是一个可执行文件,在运行测试之前,您需要将其放置在系统路径之一中。
Firefox浏览器使用名为GeckoDriver.exe的可执行文件来实现WebDriver协议。 Selenium使用WebDriver协议将请求发送到GeckoDriver,后者将呼叫转换为Marionette自动化协议,Firefox将理解以Marionette协议形式传输的命令并执行它们。

GeckoDriver

壁虎驱动程序

没有GeckoDriver.exe的Selenium 3测试 (Selenium 3 Test without GeckoDriver.exe)

Let’s see what happens, if we run the Selenium test without GeckoDriver. It was a very straight forward process where you were not required to use GeckoDriver. You just write the code to instantiate the WebDriver and open Firefox browser. Below is the sample program to launch a Firefox browser with Selenium 2.0

让我们看看如果在没有GeckoDriver的情况下运行Selenium测试会发生什么。 这是一个非常简单的过程,不需要您使用GeckoDriver。 您只需编写代码以实例化WebDriver并打开Firefox浏览器。 以下是使用Selenium 2.0启动Firefox浏览器的示例程序


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

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.gecko.driver.

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

Exception

例外

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

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

下载并安装Gecko驱动程序 (Download and Install Gecko Driver)

Gecko Driver is available as an executable file that starts as a server on your system. The following are the steps to download Gecko Driver.

Gecko驱动程序作为可执行文件提供,该文件作为系统上的服务器启动。 以下是下载Gecko驱动程序的步骤。

  • Step 1: Go to the Eclipse official website and select appropriate version for GeckoDriver based on your operating system步骤1 :转到Eclipse官方网站 ,然后根据您的操作系统为GeckoDriver选择适当的版本
  • Note: Here we are working on Windows Operating system, we need to download the corresponding Gecko driver of Windows version. If your Operating System is Linux or Mac then you need to download the corresponding Gecko driver.

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

    GeckoDriver Version

    GeckoDriver版本

  • Step 2: Once the ZIP file download is complete, extract the ZIP file步骤2 :ZIP文件下载完成后,解压缩ZIP文件
  • GeckoDriver Extraction

    GeckoDriver提取

  • Step 3: Note the location where you extracted the geckodriver. Location will be later used to instantiate the driver步骤3 :记下提取geckodriver的位置。 位置将在以后用于实例化驱动程序
  • GeckoDriver Location

    GeckoDriver位置

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

    There are 2 methods to initialize GeckoDriver.

    有两种初始化GeckoDriver的方法。

    设置Gecko驱动程序的系统属性:- (Set System Properties for Gecko Driver:-)

    Code to set the System properties is

    设置系统属性的代码是

    System.setProperty(“webdriver.gecko.driver”,“Path to geckodriver.exe”);

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

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

    
    package com.journaldev.selenium.Firefox;import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;public class GeckoDriver {public static void main(String[] args) {System.setproperty("Webdriver.gecko.driver","D:\\Drivers\\geckodriver.exe");WebDriver driver = new FirefoxDriver();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 Firefox window and it will print the website title in the console.

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

    在Windows环境变量中设置Gecko驱动程序路径: (Setting Gecko Driver 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 :单击高级选项卡,然后单击环境变量。
  • Environment Variables

    环境变量

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

    路径

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

    可变值

    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 GeckoDriver will be like this:

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

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

    结论 (Conclusion)

    GeckoDriver will act as an intermediate factor between your Selenium scripts and Gecko-based browsers like Firefox. Firefox has done some changes, which has led to prevention of supporting third-party drivers to interact directly with the browsers.
    This is the main reason for which we need to use the GeckoDriver. The easiest way to use GeckoDriver in your script is to use the System.set property. [System.setProperty(“webdriver.gecko.driver”, ”Path of the Gecko Driver file”)].

    GeckoDriver将充当您的Selenium脚本和基于Firefox的基于Gecko的浏览器之间的中间因素。 Firefox进行了一些更改,从而导致无法支持第三方驱动程序直接与浏览器进行交互。
    这是我们需要使用GeckoDriver的主要原因。 在脚本中使用GeckoDriver的最简单方法是使用System.set属性。 [System.setProperty(“ webdriver.gecko.driver”,“ Gecko驱动程序文件的路径”))。

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

    selenium火狐驱动

selenium火狐驱动_在Selenium Firefox驱动程序上运行测试相关推荐

  1. selenium 解析网页_用Selenium进行网页搜刮

    selenium 解析网页 网页抓取系列 (WEB SCRAPING SERIES) 总览 (Overview) Selenium is a portable framework for testin ...

  2. selenium无头浏览器_无头Selenium浏览器

    selenium无头浏览器 重要要点 无头浏览器无需用户界面即可运行. 不再支持PhantomJS. JBrowser驱动程序是Java 8的低开销选项. 如果需要Java 11支持,所有当前的Jav ...

  3. selenium基础教程_弹性Selenium基础设施

    selenium基础教程 HelloFresh values a strong user experience, so proper testing is at the core of how we ...

  4. 在Selenium Chrome驱动程序上运行测试

    Chrome browser implements the WebDriver protocol by using an executable file called ChromeDriver.exe ...

  5. selenium查找文本_在Selenium中查找具有链接文本和部分链接文本的元素

    selenium查找文本 Selenium中CSS定位器是一个基本概念,每个旨在使用Selenium执行自动化测试的测试人员都应该意识到这一点. 在Selenium中充分使用CSS定位器可以帮助您以更 ...

  6. selenium抓取_使用Selenium的网络抓取电子商务网站

    selenium抓取 In this article we will go through a web scraping process of an E-Commerce website. I hav ...

  7. Php使用selenium爬虫,selenium,python爬虫_使用selenium爬取网站时输出结果不正确,selenium,python爬虫 - phpStudy...

    使用selenium爬取网站时输出结果不正确 网站链接:http://www.ncbi.nlm.nih.gov/pubmed?term=(%222013%22%5BDate%20-%20Publica ...

  8. selenium持续集成_使用Selenium进行Spring Boot集成测试

    selenium持续集成 Web集成测试允许对Spring Boot应用程序进行集成测试,而无需进行任何模拟. 通过使用@WebIntegrationTest和@SpringApplicationCo ...

  9. c# selenium chrome 文件下载_使用selenium从网站下载文件

    from selenium import webdriver from time import sleep import datetime import os import shutil import ...

最新文章

  1. 征战蓝桥 —— 2014年第五届 —— C/C++A组第9题——斐波那契
  2. 关于界面软件测试点,电子商务网站--界面测试的测试点
  3. 二叉树的三种遍历(递归与非递归) + 层次遍历
  4. WPF程序模彷Windows7的桌面任务栏
  5. macOS Big Sur 配置 jdk
  6. UED、UCD、UE、UI、交互设计概念
  7. 编译Android源码致命错误解决方案
  8. zabbix监控第一台服务器(10)
  9. 【生信进阶练习1000days】day8-OrganismDb.dplyr包
  10. 前端知识点——Web Sockets
  11. DiskPart-删除磁盘分区
  12. php解密encrypteddata,PHP解密支付宝小程序的加密数据、手机号的示例代码
  13. 桌面点击:右键点击-显示设置,提示“该文件没有与之关联的程序来执行该操作“解决方法总结
  14. python批量修改替换文件内容
  15. 九。温暖地待人,你才会得到意想不到的惊喜结果。
  16. php 分数相同怎么排名,怎么算出成绩排名_学校班级成绩排名计算方法
  17. 计算机到路由器用交叉线的好处,路由器与交换机连接-路由器和交换机之间是用交叉线还是用直通线联 – 手机爱问...
  18. 巧妙复制网页中的文本——复制网页上不能复制的文字
  19. 靶机11 Empire Lupin One
  20. ios13全选手势_苹果手机双指、三指等操作手势,升级iOS13之后,居然多了这么多新操作?...

热门文章

  1. Paypal Rest Api自定义物流地址(跳过填写物流地址)
  2. C#获取文件夹下的所有文件名
  3. [转载] 两种方法分割python多空格字符串
  4. [转载] PYTHON 字符串转换为二进制字符串,二进制字符串转换为字符串
  5. [转载] python 闭包和装饰器详解
  6. LESS是一个CSS预处理器,跨浏览器友好,提供诸如变量,函数, mixins 和操作等功能,可以构建动态CSS...
  7. ava集合---ArrayList的实现原理
  8. 牛客Wannafly挑战赛10 A.小H和迷宫
  9. 使用maven在netbeans下构建wicket项目
  10. MVVM模式下 触发器多条件判断