WebDriverException:断开连接:即使提供最新chromedriver的正确路径也无法连接到渲染器

时间:2019-03-09 09:27:46

标签: java selenium selenium-webdriver webdriver selenium-chromedriver

package Testing_Forum;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class XTR {

    public static void main(String arg[]) {
    System.getProperty("webdriver.chrome.driver,D:\\Important\\chromedriver_win32_important\\chromedriver.exe");

        WebDriver driver=new ChromeDriver();
        driver.get("https://www.google.com/");
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(1000, TimeUnit.SECONDS);
    }
}

它将正确打开浏览器,但使用旧的chromedriver,即chromedriver版本2.31。我已经删除了此版本的驱动程序并安装了2.46,甚至在System.getProperty中提到了正确的路径。您能帮我解决这个问题吗?

我得到的输出是:

Exception in thread "main" org.openqa.selenium.WebDriverException: disconnected: unable to connect to renderer
  (Session info: chrome=72.0.3626.119)
  (Driver info: chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=Windows NT 10.0.17134 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:32.194Z'
System info: host: 'DESKTOP-P5LJI3P', ip: '192.168.0.100', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_191'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptSslCerts: true, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.31.488763 (092de99f48a300..., userDataDir: C:\Users\Dell\AppData\Local...}, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 72.0.3626.119, webStorageEnabled: true}
Session ID: 2b066d8eb4b2d3e783abfb1e0836b749

2 个答案:

答案 0 :(得分:1)

代替使用System.getProperty(),您需要传递包含{{1的绝对路径 Key Value 部分。 }}分别通过 chromedriver.exe 行,如下所示:

System.setProperty()

答案 1 :(得分:0)

我建议您使用WebDriverManager,因为WebDriverManager会获取浏览器版本并以自动方式下载相关的二进制文件/可执行文件;这可以帮助我们避免之前为了执行测试而必须执行的所有与浏览器驱动程序设置有关的手动步骤。

    WebDriver driver;
    case WebDriverType.CHROME:
                    WebDriverManager.chromedriver().setup();
                    ChromeOptions cOptions = new ChromeOptions();
                    cOptions.addArguments("--ignore-certificate-errors");
                    cOptions.addArguments("disable-infobars");
                    cOptions.addArguments("test-type");
                    cOptions.addArguments("--disable-extensions");
                    cOptions.addArguments("--disable-notifications");
                    cOptions.addArguments("--disable-component-update");
                    cOptions.addArguments("start-maximized");
                    driver = new ChromeDriver(cOptions);

别忘了在POM.XML中添加以下依赖项

    <dependency>
        <groupId>io.github.bonigarcia</groupId>
        <artifactId>webdrivermanager</artifactId>
        <version>${webdrivermanager.version}</version>
    </dependency>

如果这样做,则无需像这样操作就下载并设置chromedriver.exe的路径

System.getProperty("webdriver.chrome.driver,D:\\Important\\chromedriver_win32_important\\chromedriver.exe");