【问题标题】:Firefox browser is not opening in Selenium webdriver in eclipseFirefox 浏览器未在 Eclipse 中的 Selenium webdriver 中打开
【发布时间】:2017-08-25 11:41:22
【问题描述】:

我使用的是 Firefox 45.8.0 版本,我尝试使用以下代码打开 Firefox 浏览器,但出现错误:“驱动程序可执行文件的路径必须由 webdriver.gecko.driver 系统属性设置”。 请告诉我如何设置路径。 注意:gecko 驱动适用于 firefox 48 以上版本。

package First;

    import org.openqa.selenium.firefox.FirefoxDriver;
    public class City {

        public static void main(String[] args) {
            // TODO Auto-generated method stub

            FirefoxDriver c1=new FirefoxDriver();
            c1.get("http://google.com");

        }

    }

【问题讨论】:

标签: java eclipse selenium firefox


【解决方案1】:

试试下面的代码。

在您的代码中,您没有提供gecko driver path。你可以从这个link下载gecko驱动

public class City {

    public static void main(String[] args) {

        System.setProperty("webdriver.gecko.driver", "C:\\Drivers\\geckodriver.exe");
        WebDriver driver = new FirefoxDriver();
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS);
        driver.get("http://google.com");  
    }
}

【讨论】:

  • 在传递 url 之前引入 ImplicitlyWait 的任何具体原因?
  • 是的,有时浏览器可能需要一些时间才能打开浏览器。所以最好先打开浏览器再传url。如果您不提供隐式等待,那么有时您会收到类似element not found 的错误,因为浏览器仍未打开并且驱动程序会移动到下一个元素。
  • @Dev 隐式等待为驱动程序设置一次,并持续驱动程序的生命周期。它实际上并没有在设置时等待,因此无论是在 .get() 之前还是之后设置都没有关系。
猜你喜欢
  • 2017-01-13
  • 2017-10-23
  • 2017-06-25
  • 2012-04-08
  • 1970-01-01
  • 2020-06-26
  • 2017-01-19
  • 1970-01-01
  • 2018-01-02
相关资源
最近更新 更多