org.openqa.selenium.WebDriverException: disconnected: received Inspector.detached event error during test execution using Selenium and Chromedriver

霸气de小男生 提交于 2021-02-16 21:07:03

问题


I know that Selenium is an automated testing tool, but i'm trying to use it for RPA instead (things to do with my work environment)

I've gotten the java code down, and it runs exactly how i want it. It takes data from an excel sheet, converts the data into java objects, then enters data into a web application. It works fine for the first 20-25 entries, then starts to slow down, and eventually crashes the application. I have a few thousand rows to enter.

I've tried starting the chrome webdriver with disabled cache, but doesn't solve the problem.

Here is the code for disabling the cache.

System.setProperty("webdriver.chrome.driver","C:\\\\DRIVERS\\\\chromedriver.exe");
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability("applicationCacheEnabled", false);
WebDriver webDriver = new ChromeDriver(cap);
WebDriverWait wait = new WebDriverWait(webDriver, 20);
JavascriptExecutor js = (JavascriptExecutor) webDriver;

I'm using a for each loop to key in the data.

/* Add vehicle data */
            for(VehicleData vehicleData : testDataList) {

                Thread.sleep(2500);

                /* Add new inspection */

                webDriver.findElement(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/div[2]/div/mat-tab-group/div/mat-tab-body[1]/div/div[2]/div/div/button")).click();

                js.executeScript("window.scrollBy(0,-1000)");

                DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd/MM/yyyy");
                LocalDateTime now = LocalDateTime.now();
                String inspectionDate = dtf.format(now).toString();

                Thread.sleep(5000);

                webDriver.findElement(By.name("InspectionDate")).click();
                webDriver.findElement(By.name("InspectionDate")).sendKeys(inspectionDate);
                webDriver.findElement(By.name("InspectionDate")).sendKeys(Keys.ESCAPE);

                Thread.sleep(1000);

                webDriver.findElement(By.id("cmbCity")).sendKeys(vehicleData.getCityMaster());
                webDriver.findElement(By.id("cmbCity")).sendKeys(Keys.ARROW_DOWN);
                webDriver.findElement(By.id("cmbCity")).sendKeys(Keys.ENTER);

                Thread.sleep(1000);

                webDriver.findElement(By.id("cmbvehicleTypeNew")).sendKeys(surveyType);
                webDriver.findElement(By.id("cmbvehicleTypeNew")).sendKeys(Keys.ARROW_DOWN);
                webDriver.findElement(By.id("cmbvehicleTypeNew")).sendKeys(Keys.ENTER);

                Thread.sleep(1000);

                webDriver.findElement(By.id("cmbWheel")).sendKeys("4");
                webDriver.findElement(By.id("cmbWheel")).sendKeys(Keys.ARROW_DOWN);
                webDriver.findElement(By.id("cmbWheel")).sendKeys(Keys.ENTER);

                Thread.sleep(1000);

                webDriver.findElement(By.id("maker")).sendKeys(vehicleData.getMake());
                webDriver.findElement(By.id("maker")).sendKeys(Keys.ARROW_DOWN);
                webDriver.findElement(By.id("maker")).sendKeys(Keys.ENTER);

                Thread.sleep(1000);

                webDriver.findElement(By.id("model")).sendKeys(vehicleData.getModelMaster());
                webDriver.findElement(By.id("model")).sendKeys(Keys.ARROW_DOWN);
                webDriver.findElement(By.id("model")).sendKeys(Keys.ENTER);

                Thread.sleep(1000);

                webDriver.findElement(By.id("cmbchassis")).click();
                webDriver.findElement(By.id("cmbchassis")).sendKeys("2s-2d");

                Thread.sleep(1000);

                webDriver.findElement(By.id("cmbchassis")).sendKeys(Keys.ARROW_DOWN);
                webDriver.findElement(By.id("cmbchassis")).sendKeys(Keys.ENTER);

                Thread.sleep(3000);

                js.executeScript("window.scrollBy(0,1000)");

                /* Enter Front Left Data */
                wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[2]/form/div[10]/kendo-grid/div/table/tbody/tr[1]/td[2]/div[1]/mat-form-field/div/div[1]/div/input"))).sendKeys(vehicleData.getSizeFL());
                wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[2]/form/div[10]/kendo-grid/div/table/tbody/tr[1]/td[2]/div[1]/mat-form-field/div/div[1]/div/input"))).sendKeys(Keys.ARROW_DOWN);
                wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[2]/form/div[10]/kendo-grid/div/table/tbody/tr[1]/td[2]/div[1]/mat-form-field/div/div[1]/div/input"))).sendKeys(Keys.ENTER);

                Thread.sleep(1000);

                webDriver.findElement(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[2]/form/div[10]/kendo-grid/div/table/tbody/tr[1]/td[2]/div[2]/div[1]/mat-form-field/div/div[1]/div/input")).sendKeys(vehicleData.getBrandFL());
                webDriver.findElement(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[2]/form/div[10]/kendo-grid/div/table/tbody/tr[1]/td[2]/div[2]/div[1]/mat-form-field/div/div[1]/div/input")).sendKeys(Keys.ARROW_DOWN);
                webDriver.findElement(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[2]/form/div[10]/kendo-grid/div/table/tbody/tr[1]/td[2]/div[2]/div[1]/mat-form-field/div/div[1]/div/input")).sendKeys(Keys.ENTER);

                Thread.sleep(1000);

                webDriver.findElement(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[2]/form/div[10]/kendo-grid/div/table/tbody/tr[1]/td[2]/div[2]/div[2]/mat-form-field/div/div[1]/div/input")).sendKeys(vehicleData.getPatternFL());
                webDriver.findElement(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[2]/form/div[10]/kendo-grid/div/table/tbody/tr[1]/td[2]/div[2]/div[2]/mat-form-field/div/div[1]/div/input")).sendKeys(Keys.ARROW_DOWN);
                webDriver.findElement(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[2]/form/div[10]/kendo-grid/div/table/tbody/tr[1]/td[2]/div[2]/div[2]/mat-form-field/div/div[1]/div/input")).sendKeys(Keys.ENTER);

                /* Enter Front Right Data */
                wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[2]/form/div[10]/kendo-grid/div/table/tbody/tr[2]/td[2]/div[1]/mat-form-field/div/div[1]/div/input"))).sendKeys(vehicleData.getSizeFR());
                wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[2]/form/div[10]/kendo-grid/div/table/tbody/tr[2]/td[2]/div[1]/mat-form-field/div/div[1]/div/input"))).sendKeys(Keys.ARROW_DOWN);
                wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[2]/form/div[10]/kendo-grid/div/table/tbody/tr[2]/td[2]/div[1]/mat-form-field/div/div[1]/div/input"))).sendKeys(Keys.ENTER);

                Thread.sleep(1000);

                webDriver.findElement(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[2]/form/div[10]/kendo-grid/div/table/tbody/tr[2]/td[2]/div[2]/div[1]/mat-form-field/div/div[1]/div/input")).sendKeys(vehicleData.getBrandFR());
                webDriver.findElement(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[2]/form/div[10]/kendo-grid/div/table/tbody/tr[2]/td[2]/div[2]/div[1]/mat-form-field/div/div[1]/div/input")).sendKeys(Keys.ARROW_DOWN);
                webDriver.findElement(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[2]/form/div[10]/kendo-grid/div/table/tbody/tr[2]/td[2]/div[2]/div[1]/mat-form-field/div/div[1]/div/input")).sendKeys(Keys.ENTER);

                Thread.sleep(1000);

                webDriver.findElement(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[2]/form/div[10]/kendo-grid/div/table/tbody/tr[2]/td[2]/div[2]/div[2]/mat-form-field/div/div[1]/div/input")).sendKeys(vehicleData.getPatternFR());
                webDriver.findElement(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[2]/form/div[10]/kendo-grid/div/table/tbody/tr[2]/td[2]/div[2]/div[2]/mat-form-field/div/div[1]/div/input")).sendKeys(Keys.ARROW_DOWN);
                webDriver.findElement(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[2]/form/div[10]/kendo-grid/div/table/tbody/tr[2]/td[2]/div[2]/div[2]/mat-form-field/div/div[1]/div/input")).sendKeys(Keys.ENTER);

                /* Enter Rear Left Data */
                wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[2]/form/div[10]/kendo-grid/div/table/tbody/tr[3]/td[2]/div[1]/mat-form-field/div/div[1]/div/input"))).sendKeys(vehicleData.getSizeRL());
                wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[2]/form/div[10]/kendo-grid/div/table/tbody/tr[3]/td[2]/div[1]/mat-form-field/div/div[1]/div/input"))).sendKeys(Keys.ARROW_DOWN);
                wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[2]/form/div[10]/kendo-grid/div/table/tbody/tr[3]/td[2]/div[1]/mat-form-field/div/div[1]/div/input"))).sendKeys(Keys.ENTER);

                Thread.sleep(1000);

                webDriver.findElement(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[2]/form/div[10]/kendo-grid/div/table/tbody/tr[3]/td[2]/div[2]/div[1]/mat-form-field/div/div[1]/div/input")).sendKeys(vehicleData.getBrandRL());
                webDriver.findElement(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[2]/form/div[10]/kendo-grid/div/table/tbody/tr[3]/td[2]/div[2]/div[1]/mat-form-field/div/div[1]/div/input")).sendKeys(Keys.ARROW_DOWN);
                webDriver.findElement(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[2]/form/div[10]/kendo-grid/div/table/tbody/tr[3]/td[2]/div[2]/div[1]/mat-form-field/div/div[1]/div/input")).sendKeys(Keys.ENTER);

                Thread.sleep(1000);

                webDriver.findElement(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[2]/form/div[10]/kendo-grid/div/table/tbody/tr[3]/td[2]/div[2]/div[2]/mat-form-field/div/div[1]/div/input")).sendKeys(vehicleData.getPatternRL());
                webDriver.findElement(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[2]/form/div[10]/kendo-grid/div/table/tbody/tr[3]/td[2]/div[2]/div[2]/mat-form-field/div/div[1]/div/input")).sendKeys(Keys.ARROW_DOWN);
                webDriver.findElement(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[2]/form/div[10]/kendo-grid/div/table/tbody/tr[3]/td[2]/div[2]/div[2]/mat-form-field/div/div[1]/div/input")).sendKeys(Keys.ENTER);

                /* Enter Rear Right Data */
                wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[2]/form/div[10]/kendo-grid/div/table/tbody/tr[4]/td[2]/div[1]/mat-form-field/div/div[1]/div/input"))).sendKeys(vehicleData.getSizeRL());
                wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[2]/form/div[10]/kendo-grid/div/table/tbody/tr[4]/td[2]/div[1]/mat-form-field/div/div[1]/div/input"))).sendKeys(Keys.ARROW_DOWN);
                wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[2]/form/div[10]/kendo-grid/div/table/tbody/tr[4]/td[2]/div[1]/mat-form-field/div/div[1]/div/input"))).sendKeys(Keys.ENTER);

                Thread.sleep(1000);

                webDriver.findElement(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[2]/form/div[10]/kendo-grid/div/table/tbody/tr[4]/td[2]/div[2]/div[1]/mat-form-field/div/div[1]/div/input")).sendKeys(vehicleData.getBrandRL());
                webDriver.findElement(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[2]/form/div[10]/kendo-grid/div/table/tbody/tr[4]/td[2]/div[2]/div[1]/mat-form-field/div/div[1]/div/input")).sendKeys(Keys.ARROW_DOWN);
                webDriver.findElement(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[2]/form/div[10]/kendo-grid/div/table/tbody/tr[4]/td[2]/div[2]/div[1]/mat-form-field/div/div[1]/div/input")).sendKeys(Keys.ENTER);

                Thread.sleep(1000);

                webDriver.findElement(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[2]/form/div[10]/kendo-grid/div/table/tbody/tr[4]/td[2]/div[2]/div[2]/mat-form-field/div/div[1]/div/input")).sendKeys(vehicleData.getPatternRL());
                webDriver.findElement(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[2]/form/div[10]/kendo-grid/div/table/tbody/tr[4]/td[2]/div[2]/div[2]/mat-form-field/div/div[1]/div/input")).sendKeys(Keys.ARROW_DOWN);
                webDriver.findElement(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[2]/form/div[10]/kendo-grid/div/table/tbody/tr[4]/td[2]/div[2]/div[2]/mat-form-field/div/div[1]/div/input")).sendKeys(Keys.ENTER);

                Thread.sleep(1000);

                webDriver.findElement(By.xpath("/html/body/app-component/div/div/mat-sidenav-container/mat-sidenav-content/div[1]/div[2]/count-survey-component/count-survey-vehicle/count-survey-addedit-inspection/div[1]/span[3]/button")).click();

                Thread.sleep(2500);

                js.executeScript("window.scrollTo(0,0)");

Error is:

    [1576641990.504][WARNING]: Timed out connecting to Chrome, retrying...
[1576644529.565][SEVERE]: Timed out receiving message from renderer: 600.000
org.openqa.selenium.TimeoutException: timeout
  (Session info: chrome=79.0.3945.79)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'SGLT009696', ip: '10.225.5.54', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '12.0.2'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 79.0.3945.79, chrome: {chromedriverVersion: 78.0.3904.70 (edb9c9f3de024..., userDataDir: C:\Users\RAY~1.TON\AppData\...}, goog:chromeOptions: {debuggerAddress: localhost:61927}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 9a644474b16f372400389760be2c942b
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
    at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:489)
    at rpa.EnterDataToWeb.enterDataToWeb(EnterDataToWeb.java:152)
    at Main.main(Main.java:174)

I've read that this happens when trying to open Chrome DevTools during the test, but my code does not do that at all. Please advise.

Is it an issue with the chrome cache filling up? If so, must i clear it every 30 or so entries?


回答1:


This error message...

org.openqa.selenium.WebDriverException: disconnected: received Inspector.detached event

...implies that the WebDriverException was raised due to Inspector.detached event.


From your code trials it is pretty much evident you were using Thread.sleep(n); to wait for the elements to be clickable / interacable to invoke sendKeys() which is not the ideal way, as:

Thread.sleep() suspends the execution of the current thread for the given number of seconds. The argument may be a floating point number to indicate a more precise sleep time. The actual suspension time may be less than that requested because any caught signal will terminate the sleep() following execution of that signal’s catching routine. Also, the suspension time may be longer than requested by an arbitrary amount because of the scheduling of other activity in the system.

Invoking sendKeys() and Thread.sleep() back to back might have simulated sending either of the following:

  • Ctrl + Shift + I
  • Ctrl + Shift + J
  • Ctrl + Shift + C
  • F12

each of which will attempt to open the google-chrome-devtools

Now, as per the article DevTools window keeps closing if you try to open the google-chrome-devtools, ChromeDriver is automatically disconnected.


Solution

A full proof solution will be to replace all the instances of Thread.sleep() and ImplicitWait with ExplicitWait


Additional Consideration

As per the documentation of DesiredCapabilities, the applicationCacheEnabled is a read/write capability which takes a boolean value and configures whether the session can interact with the application cache.


Implementation

applicationCacheEnabled can be configured in either of the ways:

DesiredCapabilities capability = DesiredCapabilities.chrome();
capability.setCapability("applicationCacheEnabled", false);

Or

DesiredCapabilities capability = DesiredCapabilities.chrome();
capability.setCapability(CapabilityType.SUPPORTS_APPLICATION_CACHE, false);

So effectively your code block will be:

System.setProperty("webdriver.chrome.driver","C:\\DRIVERS\\chromedriver.exe");
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(CapabilityType.SUPPORTS_APPLICATION_CACHE, false);
ChromeOptions opt = new ChromeOptions();
opt.merge(cap);
WebDriver driver = new ChromeDriver(opt);

Reference

You can find a relevant discussion in:

  • How to fix unknown error: unhandled inspector error: “Cannot find context with specified id”



回答2:


Just add this line:

chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);

This should solve the problem.



来源:https://stackoverflow.com/questions/59369088/org-openqa-selenium-webdriverexception-disconnected-received-inspector-detache

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