我正在尝试使用 chromedriver 运行 Selenium 测试。要在启动时隐藏 chrome 窗口,我使用以下代码。引用https://sqa.stackexchange.com/a/15489 .
driver.manage().window().setPosition(new Point(-2000, 0));
上面的代码在我的本地 Windows 7 操作系统和另一台运行 Windows 8 的远程计算机中运行良好,但在运行 Windows 10 的一台远程计算机中失败并出现以下异常。
[66.916][SEVERE]: Timed out receiving message from renderer: -11.117
Exception in Main org.openqa.selenium.WebDriverException: unknown error: cannot get automation extension
from timeout
对于这个异常(exception),我在网上找到的每个答案都只涉及将 chromedriver 和 chrome 更新到最新版本,我已经这样做了。
我在所有操作系统上使用相同的版本: Chrome 驱动程序:2.29.461591 Chrome 版本:58.0.3029.110 Selenium 版本:2.33.0
失败的操作系统信息: Windows 10 家庭版 64 位
任何帮助将不胜感激,谢谢。
最佳答案
只是预感 - 由于您的操作系统是 64 位,因此您的 Chrome 浏览器很可能也是 64 位。您可能还安装了 32 位 chrome,并且 webdriver 正在启动可能未更新的 32 位? (同样只是一种预感)。
首先检查您的系统是 32 位还是 64 位。您应该能够通过点击“Chrome 帮助”>“关于 Google Chrome”来辨别差异。
与下面显示的不同,32 位版本号旁边不会有“(64 位)”文本。
现在将版本与 webdriver 启动的版本进行比较,然后再出现错误。
如果不同,请尝试通过执行以下操作来设置二进制文件:
ChromeOptions options = new ChromeOptions();
options.setBinary("path/to/latest/64-bit/chrome/Chrome.exe");
System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, "path/to/chrome/driver/chromedriver");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(capabilities);
只是一个预感,但希望有帮助。
PS。我在我的机器 Win7 64 位上尝试了同样的操作,它可以正常工作。关于Java-Selenium 2 : Chromedriver - Exception calling driver. 管理().window().setPosition(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44015977/