我尝试使用 Selenium 在 Java 上运行这个简单的程序:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class MySelenium {
public static void main(String[] args) {
System.out.println("First Selenium");
System.setProperty("webdriver.chrome.driver", "C:\\automation\\drivers\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.seleniumhq.org/");
driver.quit();
}
}
但运行时出现以下错误:
我该如何修复这个错误?
这个错误信息...
org.openqa.selenium.SessionNotCreatedException: session not created
disconnected: unable to send message to renderer
...意味着Chrome驱动程序无法启动/产生新的网页浏览器 i.e. Chrome浏览器会议。
我怀疑你的主要问题是不兼容您正在使用的二进制文件的版本之间。
根据您提供的快照,您正在使用的以下一组二进制文件对我来说看起来很好:
-
JDK: 1.8.0_191
-
Selenium: 3.14.0
-
Chrome驱动程序: 2.43
-
Chrome: 69.0
分析及解决方案
As per 使用 chrome 驱动程序 2.27 无法接收来自渲染器错误的消息 https://bugs.chromium.org/p/chromedriver/issues/detail?id=1651另一个潜在的原因可能是存在防病毒软件在你的本地主机你需要的disable.
-
确保这件事/etc/主机您的系统上包含以下条目:
127.0.0.1 localhost.localdomain localhost
#or
127.0.0.1 localhost loopback
Keep Chrome版本之间铬 v68-70水平。 (根据 ChromeDriver v2.43 发行说明 https://chromedriver.storage.googleapis.com/2.43/notes.txt)
-
Clean your 项目工作区通过你的IDE and Rebuild您的项目仅具有所需的依赖项。
- (仅限 Windows 操作系统) Use CCleaner https://www.ccleaner.com/ccleaner工具可以清除执行之前和之后的所有操作系统杂务测试套件.
- (仅限 Linux 操作系统) 释放 Ubuntu/Linux Mint 中未使用/缓存的内存 http://www.yourownlinux.com/2013/10/how-to-free-up-release-unused-cached-memory-in-linux.html在执行你的之前和之后测试套件.
- 如果你的基地网页客户端版本太旧,然后通过卸载雷沃卸载程序 https://www.revouninstaller.com/revo_uninstaller_free_download.html并安装最新的 GA 和发布版本网页客户端.
- Take a 系统重启.
- 执行你的
@Test
.
参考
您可以在以下位置找到相关讨论自动化测试错误:org.openqa.selenium.WebDriverException:已断开连接:无法连接到渲染器 https://stackoverflow.com/questions/48642014/automation-testing-error-org-openqa-selenium-webdriverexception-disconnected
tl;dr
As per 也观察到了这个问题Chrome 驱动程序 2.38 and 铬 67+组合并与相关静态 iframe(最初加载的 DOM 的一部分)似乎可以正常工作,直到铬66.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)