Reputation: 60
I have a button click command in Katalon Studio where I use scrollIntoView to bring a button into view and then click the button.
((JavascriptExecutor) functiondriver).executeScript("arguments[0].scrollIntoView({block: \"nearest\"});", buttonelement);
WebUI.delay(4)
WebUI.click(findTestObject('object/path'))
Using Chrome on execution, the code works fine on a Windows computer, but then on a Mac computer I get the following error about 40% of the time:
Unable to click on object '/object/path/' (Root cause: org.openqa.selenium.WebDriverException: unknown error: Element <button class="classname">...</button> is not clickable at point (750, 548). Other element would receive the click: <html lang="en">...</html>
I looked around the web for solutions and attempted to solve this by adding the delay you see above, but that didn't work. Furthermore, when looking at the browser as the automation was running, I can visually see the button that is supposed to be clicked - so it is not like the button is not loading. Is there another way I can write this code so that it works more consistently?
Update: I have tried the more intelligent wait function suggested both in this answer and the related question, but neither worked. I would like to stress that this problem only occurs on Mac machines, not Windows; this is what makes this problem different from other similar questions.
I did make a discovery. When running the script via Katalon Studio, Chrome by default does not maximize the window. However, I did an experiment where I forced the browser to maximize and that solved the problem. So it seems that Katalon Studio is having trouble setting x,y coordinates on a Mac when the browser is not full screen. Is this some sort of calibration issue with my install or known behavior with WebUI on Mac machines?
Upvotes: 1
Views: 1831
Reputation: 60
I finally found the issue. Macs add a scroll bar that hovers over the page content. It is invisible unless you hover over it to use it. In my case, I used "nearest" when using scroll into view, which sometimes (but not always) causes the buttom to be at the very bottom of the page. The horizontal scrollbar is in this case hovering over the button. This is why the problem disappeared when I maximized the window, and why the problem does not occur on Windows machines. I solved this problem by changing my scrollIntoView script to:
scrollIntoView({block: \"center\"}
Upvotes: 1
Reputation: 1675
Delaying is a big part of automation, sometimes the button appears to be there, but at that instant in time when it was to be interacted with, it may not be ready yet. This timeframe is typically super small and way too fast to see with your eyes.
WebUI has a series of helpers for performing dynamic waits that wait for an element to meet some criteria instead of just always waiting for X seconds.
Instead of WebUI.delay(4)
you could try something like:
WebUI.waitForElementClickable(findTestObject('object/path'))
If the problem is indeed that it's trying to interact too quick before the page is ready to let you click the button, then this will force a delay that lasts exactly until Selenium has determined that the button is in a state that will allow you to click it.
Upvotes: 1