question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to switch to new tab using chromedriver

See original GitHub issue

The application that I’m testing using HSAC library opens a new tab when clicking on a certain button. The test script is supposed to take a screenshot of that new tab and save its content (it’s a PDF embedded in html, so its content is not easily testable). The test script uses fixture switch to next tab, but this does not work: The script still stays on the the same tab. I added some high level debugging with a scenario

|scenario|dump tabs        |
|show    |tab count        |
|show    |current tab index|

|scenario              |Show form|
|dump tabs                                       |
|click                 |Vertragsbedingungen      |
|wait                  |45    |seconds           |
|dump tabs                                       |
|seconds before timeout|20                       |
|switch to next tab                              |
|note                  |show  |save page source  |
|note                  |close tab                |
|dump tabs                                       |
|switch to previous tab                          |
|dump tabs                                       |
|seconds before timeout|5                        |

which confirms my observation: Before clicking the button the output is (1, 1), Tab count increases after clicking the button which leads to a (2, 1). But switch to next tabstill shows (2, 1):

switch-tabs-hsac-only

In order to analyse this I copied the java-code of switchToNextTab() and added some logging:

Custom switchToNextTab
    public boolean switchToMyNextTab() {
        boolean result = false;
        List<String> tabs = getTabHandles();
        int currentTab = getCurrentTabIndex(tabs);

        logger.error("tabs: " + Arrays.toString(tabs.toArray()));
        logger.error("tabs(0): size " + tabs.size() + " current " + currentTab);

        if (tabs.size() > 1 || currentTab < 0) {
            int nextTab = currentTab + 1;
            if (nextTab == tabs.size() || nextTab < 0) {
                nextTab = 0;
            }
            logger.error("tabs: goto " + nextTab);
            goToTab(tabs, nextTab);
            logger.error("tabs(2): size " + tabs.size() + " current " + getCurrentTabIndex(tabs));
            result = true;
        }
        return result;
    }

To my surprise the value of current tab indexchanges (2nd pic in attachments), but I run into timeouts for switchToMyNextTab() and every fixture method that is called afterwards.

switch-tabs-with-custom-fixture

FitNesse output on calling custom switchToNextTab
switch to my next tab 
org.openqa.selenium.TimeoutException: timeout: Timed out receiving message from renderer: 20.000
  (Session info: chrome=85.0.4183.102)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'Holgers-MacBook-Pro.local', ip: 'fe80:0:0:0:10b0:2b5d:511d:13e3%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.15.6', java.version: '13.0.2'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 85.0.4183.102, chrome: {chromedriverVersion: 85.0.4183.87 (cd6713ebf92fa..., userDataDir: /var/folders/2c/_cmd0tyx2s1...}, goog:chromeOptions: {debuggerAddress: localhost:51122}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: MAC, platformName: MAC, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: ignore, webauthn:virtualAuthenticators: true}
Session ID: f25506a1d25913a63c5cc22c2df58787
	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$RemoteTargetLocator.defaultContent(RemoteWebDriver.java:922)
	at nl.hsac.fitnesse.fixture.util.selenium.SeleniumHelper.switchToDefaultContent(SeleniumHelper.java:1308)
	at nl.hsac.fitnesse.fixture.util.selenium.SeleniumHelper.goToTab(SeleniumHelper.java:1296)
	at nl.hsac.fitnesse.fixture.slim.web.BrowserTest.goToTab(BrowserTest.java:445)
	at de.fiduciagad.kfinfi.fitnesse.Sofortkredit.switchToMyNextTab(Sofortkredit.java:47)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:567)
    ...
The execution log (the truncated part shows only a series of backtraces, none of the custom loggings):
Execution log
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.

ChromeDriver was started successfully.

Sept. 15, 2020 4:52:00 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFORMATION: Detected dialect: W3C

Sept. 15, 2020 4:52:26 PM de.fiduciagad.kfinfi.fitnesse.Sofortkredit showTabInfo
SCHWERWIEGEND: tabs: size 1 current 0

Sept. 15, 2020 4:55:26 PM de.fiduciagad.kfinfi.fitnesse.Sofortkredit switchToMyNextTab
SCHWERWIEGEND: tabs: [CDwindow-7269F2F1E351583739FF39A979105790, CDwindow-F610A691675FF3818DE082E59009C576]

Sept. 15, 2020 4:55:26 PM de.fiduciagad.kfinfi.fitnesse.Sofortkredit switchToMyNextTab
SCHWERWIEGEND: tabs(0): size 2 current 0

Sept. 15, 2020 4:55:26 PM de.fiduciagad.kfinfi.fitnesse.Sofortkredit switchToMyNextTab
SCHWERWIEGEND: tabs: goto 1

[1600181746.332][SEVERE]: Timed out receiving message from renderer: 20.000

[1600181746.333][SEVERE]: Timed out receiving message from renderer: 20.000

Unable to take screenshot for exception: null

org.openqa.selenium.TimeoutException: timeout: Timed out receiving message from renderer: 20.000
  (Session info: chrome=85.0.4183.102)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'Holgers-MacBook-Pro.local', ip: 'fe80:0:0:0:10b0:2b5d:511d:13e3%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.15.6', java.version: '13.0.2'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 85.0.4183.102, chrome: {chromedriverVersion: 85.0.4183.87 (cd6713ebf92fa..., userDataDir: /var/folders/2c/_cmd0tyx2s1...}, goog:chromeOptions: {debuggerAddress: localhost:51122}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: MAC, platformName: MAC, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: ignore, webauthn:virtualAuthenticators: true}
Session ID: f25506a1d25913a63c5cc22c2df58787

	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    ...

So my questions are:

  • Why is there a difference in behaviour of custom and library version of switchToNextTab()?
  • Am I doing something wrong, or can the behaviour be fixed somehow?

Versions: HSAC 4.19.0 FitNesse 20200501

Many thanks in advance, reators

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
fhoebencommented, Sep 22, 2020

Downloading content from a ‘data-url’ instead of ‘normal’ link is actually quite a nice feature. I created an issue to add support for that. (Maybe someone can implement a PR for it before I’ll get around to it.)

0reactions
reatorscommented, Sep 28, 2020

Unfortunately did the JsonHttpTest-version work only in one of our test environments, but in not the others. As the headers are quite different, and copy browser cookies didn’t help, and the internal processing on Angular side is different (using an “http interceptor”, whatever this means), I decided to go the other way you proposed:

Decoding the content you extracted is certainly possible, but I hadn’t seen the need before to expose that as a fixture method. JsonHttpTest can do it when such a value is present in a json response (see

https://github.com/fhoeben/hsac-fitnesse-fixtures/blob/e09c9702209eda9be089be12b32776eea3948cb2/src/main/java/nl/hsac/fitnesse/fixture/slim/JsonHttpTest.java#L82 ). The class DataUrlHelper strips the prefix and then Base64Fixture can save it to disk. At the moment I fear you have to write your own custom fixture to get this to work directly from a string.

It was roughly a copy’n’pasting of existing code. I’ll provide my solution here. It’s probably not as elegant as proposed in #347, but it works for me:

    protected Base64Fixture getBase64Fixture() {
        return new Base64Fixture();
    }

    public String createFileFromUrlEncoded(final String baseName, final String urlEncodedContent) {

        String base64Content = java.net.URLDecoder.decode(urlEncodedContent, StandardCharsets.UTF_8);
        if (DataUrlHelper.isDataUrl(base64Content)) {
            base64Content = DataUrlHelper.getData(base64Content);
        }
        Base64Fixture base64Fixture = getBase64Fixture();
        return base64Fixture.createFrom(baseName, base64Content);
    }

Calling this from a scenario:

|scenario    |download pdf as   |filename                              |
|$pdfencoded=|value of attribute|src      |on              |css=iframe |
|$pdf=       |create file       |@filename|from Url encoded|$pdfencoded|
Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to switch to new tab in Chrome in Selenium ...
I have a issue while switching to new tab in chrome, by following some links on internet i came to know it is...
Read more >
Selenium Chrome Web Driver fails to open new tab with ...
While trying to open a new tab with the command driver.switch_to.new_window('tab') Selenium returns error Failed to open new tab - no ...
Read more >
Not able to open a new URL in a new tab in Selenium
There is a bug in ChromeDriver that does not allow "Ctrl + T" from working. But you can open a link in a...
Read more >
Can't drag Google Chrome tabs on your PC? Here are ...
Some workarounds to try · 1. Restore settings to default: The first thing you may try is resetting Chrome. · 2. Check your...
Read more >
Working with windows and tabs - WebDriver
To work with the new window you will need to switch to it. If you have only two tabs or windows open, and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found