In our test set we have a ‘click refresh button’, this works flawless in browser-mode. We use Playwright and Chromium.
When in headless-mode “sometimes” the button cannot be clicked, even after adding (successful) waits on the exact xpath, being visible, stable and enabled. Any idea what could be the problem and even more how to fix it?
Some context on the setup and error logs;
Keyword 'Click' failed after retrying for 5 seconds. The last error was: TimeoutError: locator.click: Timeout 5000ms exceeded. Call log:
- waiting for locator('//generic-table//button/span[@class="p-button-icon pi pi-refresh ng-star-inserted"]')
-- locator resolved to <span data-pc-section="icon" class="p-button-icon pi pi-refresh ng-star-inserted"></span>
- attempting click action
-- waiting for element to be visible, enabled and stable
-- element is visible, enabled and stable
-- scrolling into view if needed
-- done scrolling
-- performing click action
FAIL
The actual Click is preceded by;
Browser.Wait For Elements State
xpath=//generic-table//button/span[@class="p-button-icon pi pi-refresh ng-star-inserted"] visible
Browser.Wait For Elements State
xpath=//generic-table//button/span[@class="p-button-icon pi pi-refresh ng-star-inserted"] stable
Browser.Wait For Elements State
xpath=//generic-table//button/span[@class="p-button-icon pi pi-refresh ng-star-inserted"] enabled
I’ve also added a 10 sec wait in front and tried the “Wait Until Keyword Succeeds” for a retry-mechanism until it succeeds, but still occasionally it might fail. So not always, but I guess in like 1 out of 3-4 attempts. This is really puzzling me…
I’ve seen somewhat similar scenario with Selenium in the past but also with playwright so i haven’t really tried debugging this, just rewrote the testcode to try to address this.
First off all, playwright docs at Browsers | Playwright does mention that headless by default uses slight different and/or older builds of chromium so experimenting with what browser build is used might help.
Second, take a screenshot at failure, take a screenshot before click, record a video, use highlight element for clicking, any visual queue that could help with debugging.
As a final note, Wait Until Keyword Succeeds: In these cases, i have a separate keyword that creates a promise to wait for network request or response that is triggered by the the actual click, setup that promise, click and await for promise in one keyword call, and then call that keyword with WUKS …
Also not really related to the actual failure, when I was working more with selenium, very typical scenario was like this: there was invisible div either partially or fully covering the element with higher Z order. Now, as actual user would click on the coordinates of a button, that would work because events will “bubble” to any elements underneath that location unless the element on top uses the click event.. Selenium has a hard no on these events and will only click if the selector is the topmost.. I haven’t really checked how playwright would handle this sort of case but, I’d definitely check also what elements are positioned at the click coordinates.
Get BoundingBox to get the the location of the element you are trying to click and then, with bit of js like this:
Thats from seleniumtestability but the args are X and Y coordinates, should be easy to make that into a js extension .. So, calculate the center location of the element you are trying to click and if it fails, you could try to see if selector you are trying to click is actually blocked by something by comparing the element you get from that js code versus the locator you already have…