为什么我们需要为 Chrome 和 IE 浏览器设置系统属性而不为 Firefox 浏览器设置系统属性 [英] Why do we need to set the System Property for Chrome And IE Browser and Not For Firefox Browser

查看:18
本文介绍了为什么我们需要为 Chrome 和 IE 浏览器设置系统属性而不为 Firefox 浏览器设置系统属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于 Chrome,

public class Chrome {

  public static void main(String[] args) {

        System.setProperty("webdriver.chrome.driver", "E://chromedriver.exe");
        WebDriver driver = new ChromeDriver();              
        driver.get("http://www.google.com");

    }

}

对于火狐,

public class Firefox {

      public static void main(String[] args) {

            WebDriver driver = new FirefoxDriver();              
            driver.get("http://www.google.com");

        }

    }

为什么我们需要为 Chrome 和 IE 指定 system.setProperty?

Why do we need to specify the system.setProperty for Chrome and IE?

推荐答案

我也有同样的问题,但是在挖掘之后发现,

I had also same question, but after digging I found,

WebDriver 使用原生浏览器方法.Selenium 提供内置Firefox 的驱动程序,但不适用于其他浏览器.所有驱动程序(Chrome驱动程序、IE驱动程序等)是基于使用的特殊JS引擎构建的每个浏览器.

WebDriver uses native browser approach. Selenium offers inbuilt driver for Firefox but not for other browsers. All drivers (Chrome Driver, IE driver, etc.) are built based on the special JS Engine used by each browser.

Selenium WebDriver 与 Mozilla Firefox 配合得非常好,因为它有一个内置的驱动服务器.但对于 Internet Explorer 和 Google Chrome,情况并非如此.Firefox 是最传统的浏览器,因此 Selenium WebDriver 在启动浏览器之前不需要设置任何额外的实用程序.Selenium 包会自动引用 firefox.exe 的默认位置,因此用户无需设置任何其他属性.

Selenium WebDriver works very well with Mozilla Firefox because it has a built in driver server. But the same is not true for Internet Explorer and Google Chrome. Firefox is the most traditional browser, thus Selenium WebDriver do not require any additional utility to be set before launching the browser. The Selenium package automatically references towards the default location of the firefox.exe, thus the user need not to set any other property.

如果你曾经得到驱动程序可执行文件的路径必须由 webdriver 设置.IE.驱动程序系统属性"错误或其类似措辞的 Chrome 等效项,这意味着您需要在浏览器上安装驱动程序服务器.驱动服务器管理浏览器和 Selenium 有线协议之间的调用.

If you ever get the "the path to the driver executable must be set by the webdriver. ie. driver system property" error or its similarly worded Chrome equivalent, it means that you need to install the driver servers on your browser. The driver server manages the calls between the browsers and the Selenium wire protocol.

InternetExplorerDriver 是一个独立的服务器,它实现了 WebDriver 的有线协议

The InternetExplorerDriver is a standalone server which implements WebDriver’s wire protocol

同样,Google Chrome 没有内置服务器,因此您需要一个 Chrome 驱动程序服务器来将您的 Selenium 代码传送到浏览器.您可以下载 Chrome 驱动服务器.

Similarly, Google Chrome doesn’t have a built-in server so you will need a Chrome driver server for communicating your Selenium code to the browser. You can download the Chrome driver server.

创建于这里.

这篇关于为什么我们需要为 Chrome 和 IE 浏览器设置系统属性而不为 Firefox 浏览器设置系统属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆