WebDriverException: disconnected: unable to connect to renderer even on providing correct path of latest chromedriver

我怕爱的太早我们不能终老 提交于 2021-02-16 14:52:37

问题


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);
    }
}

It opens the browser properly but uses old chromedriver i.e chromedriver version 2.31. I have deleted this version driver and installed 2.46 and even have mentioned proper path in System.getProperty. Can you please help me with this problem.

Output I get is:

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

回答1:


Instead of using System.getProperty() you need to pass the Key and Value part containing the absolute path of the chromedriver.exe seperately through the System.setProperty() line as follows:

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



回答2:


I would advise you to use WebDriverManager as WebDriverManager gets the browser version and downloads relevant binaries/executables in an automated way; This helps us to avoid all the manual steps that we previously had to do, related to browser driver setup, in order to run our tests.

    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);

Do not forget to add below dependency in POM.XML

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

If you do so, then you do not need to download and set path of chromedriver.exe as you doing like this

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


来源:https://stackoverflow.com/questions/55075864/webdriverexception-disconnected-unable-to-connect-to-renderer-even-on-providin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!