繁体   English   中英

使用RemoteWebdriver的chromedriver出现错误

[英]getting error with chromedriver using RemoteWebdriver

出现错误:

失败的配置:@BeforeMethod setUp org.openqa.selenium.WebDriverException:驱动程序可执行文件的路径必须由webdriver.chrome.driver系统属性设置;否则,必须执行以下操作: 有关更多信息,请参见http://code.google.com/p/selenium/wiki/ChromeDriver 可以从http://chromedriver.storage.googleapis.com/index.html下载最新版本。

我的代码:

capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setVersion("38.0.2125.122 m");
String strChromePath = System.getProperty("user.dir")
    + "\\webdrivers\\chromedriver.exe";
System.setProperty("webdriver.chrome.driver", strChromePath);
capability.setPlatform(org.openqa.selenium.Platform.ANY);
return new RemoteWebDriver(new URL("http://192.168.1.77:5555/wd/hub"),
        capability);

在上面的代码chromedriver上,它自身没有被调用。

然后我尝试了代码:

ChromeDriverService chromeService = new ChromeDriverService.Builder()
            .usingDriverExecutable(new File("webdrivers/chromedriver.exe"))
            .usingAnyFreePort().build();
chromeService.start();
capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setVersion("38.0.2125.122 m");
capability.setPlatform(org.openqa.selenium.Platform.ANY);
return new RemoteWebDriver(new URL("http://192.168.1.77:5555/wd/hub"),
        capability);

在执行上述代码时,可执行文件会启动,但不会调用chrome。 它引发相同的错误。 代码对于Firefox运行正常。 有什么帮助吗?

请尝试以下方法:

    WebDriver driver;

    System.setProperty("webdriver.chrome.driver", "properties/chromedriver.exe");

    driver = new ChromeDriver();

    driver.get("www.google.com");

将chrome驱动程序放在properties文件夹中。

根据您的系统(32位/ 64位) 从此处下载相关的Chrome驱动程序。 尝试先设置ChromeDriver的属性,如下所示:

File file = new File("D:\\chromedriver.exe"); //path to the chromedriver.exe so downloaded
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());

然后使用此代码:-

DesiredCapabilities capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setVersion("38.0.2125.122 m");
WebDriver driver = new RemoteWebDriver(new URL("http://192.168.1.77:5555/wd/hub"),capability);

如果不需要使用“ RemoteWebDriver” ,则可以在下面进行编码:

File file = new File("D:\\chromedriver.exe"); //path to the chromedriver.exe so downloaded
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
WebDriver driver = new ChromeDriver();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM