Unable to switch to new tab using chromedriver
See original GitHub issueThe 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 tab
still shows (2, 1):
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 index
changes (2nd pic in attachments), but I run into timeouts for switchToMyNextTab()
and every fixture method that is called afterwards.
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)
...
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:
- Created 3 years ago
- Comments:13 (7 by maintainers)
Top GitHub Comments
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.)
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: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:
Calling this from a scenario: