gpt4 book ai didi

java.lang.IllegalStateException : The path to the driver executable must be set by the webdriver. gecko.driver 系统属性

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:21:35 26 4
gpt4 key购买 nike

package com.merchantPlatform;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

public class MerchantPlatformTest {

public static void main(String[] args) {

System.getProperty("webdriver.gecko.driver", "C:\\Selenium WebDriver\\geckodriver\\geckodriver-v0.17.0-win64\\geckodriver.exe");

DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);

// Initialize WebDriver
WebDriver driver = new FirefoxDriver(capabilities);

/* This works fine for versions lesser than Selenium 3. For Selenium 3 and higher, it will throw java.lang.IllegalStateException */

// Maximize Window
driver.manage().window().maximize();

// Wait For Page To Load
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

// Navigate to MerchantPlatform URL
driver.get("http://localhost:52939/");

}

}

错误

我在 System.getProperty 中遇到以下异常

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. The latest version can be downloaded from https://github.com/mozilla/geckodriver/releases at com.google.common.base.Preconditions.checkState(Preconditions.java:738) at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124) at org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:41) at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:115) at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:330) at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:207) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:108) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:137) at com.merchantPlatform.MerchantPlatformTest.main(MerchantPlatformTest.java:20)

最佳答案

您必须使用 System.setProperty 而不是 System.getProperty,如下所示。

System.setProperty("webdriver.gecko.driver",
"C:\\Selenium WebDriver\\geckodriver\\geckodriver-v0.17.0-win64\\geckodriver.exe");

关于java.lang.IllegalStateException : The path to the driver executable must be set by the webdriver. gecko.driver 系统属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45136914/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com