flyaboveothers
flyaboveothers

Reputation: 3

Calling getWindowHandles() Again causing timeout

Here is the scenario:

  1. Click a link that opens up to a new tab.
  2. Call getWindowHandles() and switch to the new tab.
  3. Use JavaScript Executor to open up the Print PopUp
  4. Call getWindowHandles() again to switch focus to the Print PopUp

This second getWindowHandles() call is causing my script to timeout and I'm not sure why. Could someone help me figure out what's going on with this second call? Everything is working as expected until step 4

        link.click();
        ArrayList<String> handles2 = new ArrayList<String> (driver.getWindowHandles());
        driver.switchTo().window(handles2.get(1));
        
        ((JavascriptExecutor)driver).executeScript("window.print()");

        ArrayList<String> handles3 = new ArrayList<String> (driver.getWindowHandles());

Maybe useful information:

Error Message:

org.openqa.selenium.ScriptTimeoutException: script timeout (Session info: chrome=86.0.4240.183) Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03' System info: host: '', ip: '', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_261' Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities {acceptInsecureCerts: true, browserName: chrome, browserVersion: 86.0.4240.183, chrome: {chromedriverVersion: 86.0.4240.22 (..., userDataDir: C:\Users\AppData\L...}, goog:chromeOptions: {debuggerAddress: localhost:}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:virtualAuthenticators: true}

Upvotes: 0

Views: 593

Answers (1)

flyaboveothers
flyaboveothers

Reputation: 3

The issue was the print dialog causing the main thread to lock out.

You are able to use the Robot class as suggested by @pcalkins. But I used the SetTimeout function.

Reference: ChromeDriver - Timeout when trying to print page with javascript

Upvotes: 0

Related Questions