所以我想在我的树莓派 3b 上使用 chromedriver,但我得到了这个错误。
我已经安装了 linux32 位版本的 chromedriver,它也能找到驱动程序。但是在初始化驱动程序时它说:
/home/pi/Desktop/chromedriver: 1: /home/pi/Desktop/chromedriver: ELF�4���4: not found
/home/pi/Desktop/chromedriver: 2: /home/pi/Desktop/chromedriver: Syntax error: Unterminated quoted string
在那之后我得到一个超时和这个错误:
Sep 06, 2018 4:47:43 PM org.openqa.selenium.os.OsProcess checkForError
SEVERE: org.apache.commons.exec.ExecuteException: Process exited with an error: 2 (Exit value: 2)
Exception in thread "main" org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T15:15:08.936Z'
System info: host: 'raspberrypi', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'arm', os.version: '4.14.34-v7+', java.version: '1.8.0_65'
Driver info: driver.version: ChromeDriver
at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:192)
at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:178)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:79)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:207)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:130)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:168)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:157)
at xxxxxxxx.initialize(xxxxxxxx.java:39)
at xxxxxxxx.main(xxxxxxxx.java:24)
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out
waiting for [http://localhost:18689/status] to be available after 20014 ms
at
org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:100)
at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverServic
e.java:187)
... 10 more
Caused by: java.util.concurrent.TimeoutException
at java.util.concurrent.FutureTask.get(FutureTask.java:205)
at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:148)
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:75)`
我的代码:
System.out.println("Starting Bot..");
System.setProperty("webdriver.chrome.driver", "/home/pi/Desktop/chromedriver");
System.out.println("yes");
Map<String, String> mobileEmulation = new HashMap<>();
mobileEmulation.put("deviceName", "Nexus 5");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulation);
chromeOptions.addArguments("--headless");
System.out.println("yes2");
driver = new ChromeDriver(chromeOptions);
最佳答案
这个错误信息...
org.openqa.selenium.os.OsProcess checkForError
SEVERE: org.apache.commons.exec.ExecuteException: Process exited with an error: 2 (Exit value: 2)
...暗示底层操作系统无法启动 chromedriver 进程。
您的主要问题是您使用的二进制文件版本之间的不兼容,如下所示:
- 您的 Selenium 客户端 版本是 3.12.0。
- 但是您的JDK 版本是1.8.0_65,这很古老。
因此 JDK v8u65 和 Selenium Client v3.12.0 之间存在明显的不匹配。
解决方案
- 将 JDK 升级到最新级别 JDK 8u181 .
- 将 Selenium 升级到当前水平 Version 3.14.0 .
- 将 ChromeDriver 升级到当前 ChromeDriver v2.41水平。
- 将 Chrome 版本保持在 Chrome v66-68 级别之间。 ( as per ChromeDriver v2.41 release notes )
- 清理您的项目工作区,通过您的IDE 并重建您的项目,仅使用所需的依赖项。
- (仅限 WindowsOS)使用 CCleaner用于在执行您的测试套件之前和之后清除所有操作系统杂务的工具。
- (仅限 LinuxOS)Free Up and Release the Unused/Cached Memory in Ubuntu/Linux Mint在执行您的测试套件之前和之后。
- 如果您的基本 Web Client 版本太旧,请通过 Revo Uninstaller 卸载它。并安装最新的 GA 和发布版本的 Web Client。
- 系统重启。
- 执行你的
@Test
。 - 始终在
tearDown(){}
方法中调用driver.quit()
以关闭和销毁 WebDriver 和 Web 客户端 实例优雅。
关于linux - "Syntax error: Unterminated quoted string"和 "org.apache.commons.exec.ExecuteException: Process exited with an error: 2 (Exit value: 2)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52207662/