我无法使用Selenium WebBrowser Java打开任何内容 [英] I can't open anything with Selenium WebBrowser Java

查看:109
本文介绍了我无法使用Selenium WebBrowser Java打开任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Selenium打开本地文件.使用下面的代码,Firefox正在打开,但是出现错误org.openqa.selenium.WebDriverException: Timed out waiting 45 seconds for Firefox to start..

I am trying to open local files with Selenium. With the code below, Firefox is opening, but I have the error org.openqa.selenium.WebDriverException: Timed out waiting 45 seconds for Firefox to start..

    File gecko = new File("resources/geckodriver64.exe");
    System.setProperty("webdriver.gecko.driver", gecko.getAbsolutePath());

    FirefoxOptions capabilities = new FirefoxOptions();
    capabilities.setCapability("marionette", false);
    WebDriver driver = new FirefoxDriver(capabilities);

    driver.get("file:///C:/example/myfile.pdf");

有人可以帮助我吗?我在互联网上找不到任何东西.

Can someone help me ? I couldn't find anything on the internet.

推荐答案

我们现在介绍了如何使用GeckoDriver启动Firefox的部分.您首先需要下载GeckoDriver,然后设置其路径.将GeckoDriver与Selenium 3结合使用的方法有三种:

We have now come to the part where you will see how you can use GeckoDriver to launch Firefox. You will first need to download GeckoDriver and then set its path. There are three different ways to use GeckoDriver with Selenium 3:

在测试中设置系统属性 通过环境变量设置系统属性 通过设置浏览器所需功能

With setting system properties in the test With setting system properties by Environment Variable With setting up Browser Desired Capabilities

下载Gecko驱动程序:- 1-可以从Github下载不同版本的Gecko驱动程序.我建议您使用最新版本.

Download Gecko Driver:- 1- Gecko Driver different versions can be downloaded from Github. I suggest you to use the latest version.

设置Gecko驱动程序的系统属性:- 设置系统属性的代码是System.setProperty("webdriver.gecko.driver","geckodriver.exe的路径");

Set System Properties for Gecko Driver:- Code to set the System properties is System.setProperty("webdriver.gecko.driver","Path to geckodriver.exe");

启动GeckoDriver的完整程序如下:

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

package seleniumPrograms;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
public class Gecko_Driver {
public static void main(String[] args) throws InterruptedException {
    System.setProperty("webdriver.gecko.driver", "D:\\\\XXXX\\trunk\\Library\\drivers\\geckodriver.exe");
    WebDriver driver = new FirefoxDriver();
    driver.get("http://www.toolsqa.com");

    Thread.sleep(5000);
    driver.quit();
}

}

这篇关于我无法使用Selenium WebBrowser Java打开任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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