无法启动浏览器。

huangapple go评论83阅读模式
英文:

Unable to Lunch Browser

问题

目前,我已经取得了一些进展,但还差最后一步。

在我进行了修改后,我得到了下面的错误消息:

Exception in thread "main" java.lang.IllegalStateException: 驱动程序可执行文件的路径必须通过webdriver.gecko.driver系统属性进行设置;更多信息请参见https://github.com/mozilla/geckodriver。最新版本可从https://github.com/mozilla/geckodriver/releases下载
	at org.openqa.selenium.internal.Require$StateChecker.nonNull(Require.java:247)
	at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:142)
	at org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:45)
	at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:186)
	at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:405)
	at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:206)
	at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:176)
	at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:154)
	at com.simplilearn.day2.oops.LaunchBrowser.main(LaunchBrowser.java:16)
public class LaunchBrowser {

    public static void main(String[] args) {

        WebDriver driver = new FirefoxDriver();

        System.setProperty("webdriver.gecko.driver", "./drivers/geckoriver");

        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
        driver.manage().timeouts().pageLoadTimeout(90, TimeUnit.SECONDS);
        driver.get("https://www.google.com");

    }
}
英文:

So, right now I have been able to make some progress, but just one more step to go.

I got the error message below after making my changes:

> Exception in thread "main" java.lang.IllegalStateException: The path
> to the driver executable 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. The latest version can be
> downloaded from https://github.com/mozilla/geckodriver/releases at
> org.openqa.selenium.internal.Require$StateChecker.nonNull(Require.java:247)
>
> at
> org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:142)
>
> at
> org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:45)
>
> at
> org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:186)
>
> at
> org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:405)
>
> at
> org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:206)
>
> at
> org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:176)
>
> at
> org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:154)
>
> at com.simplilearn.day2.oops.LaunchBrowser.main(LaunchBrowser.java:16)

public class LaunchBrowser {

    public static void main(String[] args) {

        WebDriver driver = new FirefoxDriver();

        System.setProperty(&quot;webdriver.gecko.driver&quot;, &quot;./drivers/geckoriver&quot;);

        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(40,TimeUnit.SECONDS);
        driver.manage().timeouts().pageLoadTimeout(90, TimeUnit.SECONDS);
        driver.get(&quot;https://www.google.com&quot;);

    }
}

答案1

得分: 1

你必须先设置路径,然后才能创建一个新的FirefoxDriver()。所以只需要交换这两行代码的顺序,像这样:

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

顺便提醒一下,你的路径中似乎有一个拼写错误("geckoriver"),也许这也会导致问题。另外要注意,你应该将路径设置为 .exe 文件,而不仅仅是 .exe 文件所在的文件夹。

英文:

You have to first set the path, then you can create a new FirefoxDriver(). So just switch these two lines, like this:

System.setProperty(&quot;webdriver.gecko.driver&quot;, &quot;./drivers/geckoriver/geckodriver.exe&quot;);
WebDriver driver = new FirefoxDriver();

Btw it seems that you have a spelling error ("geckoriver") in your path, maybe that causes a problem too. Notice too that you should set the path to the .exe file, not just the folder where the .exe file is in.

huangapple
  • 本文由 发表于 2020年8月21日 15:28:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/63518389.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定