【问题标题】:select proper firefox version in selenium在 selenium 中选择正确的 Firefox 版本
【发布时间】:2018-05-17 10:53:20
【问题描述】:
我在 java (Eclipse Oxygen) 中使用 selenium。
我已经安装了 Firefox 56(运行 firebug 和 firepath 插件的旧版本)以及 Firefox Developer Edition。
默认情况下,webdriver 启动 Firefox 56。我想通过 webdriver 启动 Firefox Developer Edition。那么如何设置/更改路径呢?
【问题讨论】:
标签:
firefox
selenium-webdriver
【解决方案1】:
您可以通过在FirefoxOptions 中指定要启动的Firefox 版本的可执行文件的路径来做到这一点,您可以将其传递给FirefoxDriver 的构造函数。
例如,如果您有以下代码在您的机器上启动默认的 Firefox:
@Test
public void test() {
WebDriver driver = new FirefoxDriver();
driver.get("http://demo.borland.com");
driver.findElement(By.linkText("Demo Application")).click();
driver.quit();
}
您可以将其更改为启动 Firefox 开发者版,如下所示:
@Test
public void test() {
FirefoxOptions options = new FirefoxOptions();
options.setBinary(new FirefoxBinary(new File("C:\\Program Files\\Firefox Developer Edition\\firefox.exe")));
WebDriver driver = new FirefoxDriver(options);
driver.get("http://demo.borland.com");
driver.findElement(By.linkText("Demo Application")).click();
driver.quit();
}