gpt4 book ai didi

java - ChromeDriver 需要安装 Chrome 吗?

转载 作者:行者123 更新时间:2023-12-02 12:26:21 25 4
gpt4 key购买 nike

我有以下代码:

ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless");
webDriver = new ChromeDriver(chromeOptions);

它抛出异常:

Gtk-Message: Failed to load module "topmenu-gtk-module"
Created new window in existing browser session.
Exception in thread "main" org.openqa.selenium.WebDriverException:
Timed out waiting for driver server to start.

Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'luis', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-87-generic', java.version: '1.8.0_112'
Driver info: driver.version: ChromeDriver
at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:193)
at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:181)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:78)

我是新手,我错过了什么吗?我的主机上应该运行任何其他服务器吗?

最佳答案

首先,如果您想使用 Chrome,那么您需要从以下 URL 下载它的二进制文件:-

https://sites.google.com/a/chromium.org/chromedriver/

现在在驱动程序实例之前添加System.setProperty

System.setProperty("webdriver.chrome.driver","D:\\Workspace\\JmeterWebdriverProject\\src\\lib\\chromedriver.exe");
WebDriver driver = new ChromeDriver();

现在如果你想使用 headless 那就使用 phantomjs。这是一个稳定的构建,您可以将其用于 headless 工作。从下面的链接下载:-

http://phantomjs.org/download.html

现在在驱动程序实例之前添加System.setProperty

DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true); // not really needed: JS enabled by default
caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "C:/phantomjs.exe");
WebDriver driver = new PhantomJSDriver(caps);

请参阅下面的链接了解更多信息:-

http://seleniumworks.blogspot.in/2013/03/headless-browser-testing-using.html

希望对你有帮助:)

关于java - ChromeDriver 需要安装 Chrome 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45467822/

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