java 如何在 selenium webdriver 3.0 beta 中使用 geckodriver?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38692208/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 03:41:23  来源:igfitidea点击:

How to use geckodriver in selenium webdriver 3.0 beta?

javaseleniumselenium-webdriver

提问by Priyanshu Shekhar

How can I use geckodriver for selenium webdriver 3.0 beta release. When I instantiate firefox like:

如何将 geckodriver 用于 selenium webdriver 3.0 beta 版本。当我像这样实例化 Firefox 时:

WebDriver driver = new FirefoxDriver();
System.setProperty("webdriver.gecko.driver", "//lib//geckodriver");
driver.get("/");

I get error:

我得到错误:

Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/geckodriver.

线程“main”中的异常 java.lang.IllegalStateException:驱动程序可执行文件的路径必须由 webdriver.gecko.driver 系统属性设置;有关更多信息,请参阅 https://github.com/mozilla/geckodriver

采纳答案by Priyanshu Shekhar

Got the solution:

得到了解决方案:

System.setProperty("webdriver.gecko.driver", "pathTogeckodriver");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
WebDriver driver = new FirefoxDriver(capabilities);

回答by Anish Pillai

I have used the code as below, without setting the DesiredCapabilities and it works fine, without any issues

我使用了下面的代码,没有设置 DesiredCapabilities,它工作正常,没有任何问题

System.setProperty("webdriver.gecko.driver", "pathTogeckodriver");
WebDriver driver = new FirefoxDriver();

回答by Ankit Bhatti

Example of how to define Firefox driver in selenium 3.x series will be:

如何在 selenium 3.x 系列中定义 Firefox 驱动程序的示例将是:

WebDriver driver;
System.setProperty("webdriver.gecko.driver", "G:\Drivers\geckodriver.exe");
driver = new FirefoxDriver();

Remember this (Selenium 3.x) will also require Jave 8+ versions.

请记住这一点(Selenium 3.x)也需要 Jave 8+ 版本。

回答by s-heins

This also works:

这也有效:

System.setProperty("webdriver.firefox.marionette", "pathToGeckodriver");
FirefoxDriver driver = new FirefoxDriver();

If you put the driver in the same directory as your project you can simply use:

如果您将驱动程序放在与项目相同的目录中,您可以简单地使用:

System.setProperty("webdriver.firefox.marionette", "geckodriver");
FirefoxDriver driver = new FirefoxDriver();

(Or "geckodriver.exe"for windows.)

(或"geckodriver.exe"用于窗户。)