簡體   English   中英

org.openqa.selenium.WebDriverException: disconnected: 在使用 Selenium 和 Chromedriver 的測試執行期間收到 Inspector.detached 事件錯誤

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

我知道 Selenium 是一種自動化測試工具,但我正在嘗試將其用於 RPA(與我的工作環境有關)

我已經下載了 java 代碼,它完全按照我想要的方式運行。 它從 Excel 表中獲取數據,將數據轉換為 java 對象,然后將數據輸入到 Web 應用程序中。 它適用於前 20-25 個條目,然后開始變慢,最終使應用程序崩潰。 我有幾千行要輸入。

我試過在禁用緩存的情況下啟動 chrome webdriver,但沒有解決問題。

這是禁用緩存的代碼。

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;

我正在使用 for 每個循環來鍵入數據。

/* 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)");

錯誤是:

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

我讀到在測試期間嘗試打開 Chrome DevTools 時會發生這種情況,但我的代碼根本沒有這樣做。 請指教。

chrome緩存填滿是否有問題? 如果是這樣,我必須每 30 個左右的條目清除一次嗎?

這個錯誤信息...

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

...暗示WebDriverException由於Inspector.detached 事件而引發。


從您的代碼試驗中可以明顯看出您正在使用Thread.sleep(n); 等待元件可點擊/ interacable調用sendKeys()這是不理想的方式,如:

Thread.sleep()在給定的秒數內暫停當前線程的執行。 參數可能是一個浮點數,以指示更精確的睡眠時間。 實際的暫停時間可能比請求的少,因為任何捕獲的信號都會在執行該信號的捕獲例程后終止 sleep()。 此外,由於系統中其他活動的調度,暫停時間可能比任意數量的請求長。

sendKeys()調用sendKeys()Thread.sleep()可能模擬發送以下任一內容:

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

每個都將嘗試打開google-chrome-devtools

現在,根據文章DevTools 窗口會一直關閉,如果您嘗試打開 ,ChromeDriver 會自動斷開連接。


解決方案

一個完整的證明解決方案是用ExplicitWait替換Thread.sleep()ImplicitWait 的所有實例


額外考慮

根據DesiredCapabilities的文檔, applicationCacheEnabled是一個讀/寫功能,它采用一個boolean值並配置會話是否可以與應用程序緩存交互。


執行

applicationCacheEnabled可以通過以下任一方式進行配置:

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

或者

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

所以有效地你的代碼塊將是:

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

參考

您可以在以下位置找到相關討論:

只需添加這一行:

chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);

這應該可以解決問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM