我有以下代码:
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)
我是新来的,我错过了什么吗?应该是我主机上运行的任何其他服务器吗?
答案 0 :(得分:1)
首先,如果您想使用chrome,那么您需要从以下网址下载它的二进制文件: -
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();
如果你想使用无头,那么使用phantomjs。它是一个稳定的构建,您可以用于您的头脑干工作。从下面链接下载: -
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
希望它会对你有所帮助:)。