I’m working on automating some tests for a website, only issue is these tests run on remote machines that have a low and different display resolutions and ends up with a different perspective for the website that is zoomed in, and when this happens some elements are hidden and thus the tests fail, so I have been trying to find a way to zoom out the browser like clicking ctrl± on chrome
I tried to use Press Keys None CTRL+SUBTRACT but it didn’t work out I tried to use
execute javascript document.body.style.zoom='80% but still it cause some other issues related to moving elements from their places, does any one have any idea how to zoom out?
Zooming out can be achieved with Press Keys (CTRL and -) but this is not really a recommended approach.
A better option is don’t use Maximize Browser Window, but instead use Set Window Size to set the browser window to a consistent size e.g. 1920x1080. I’m pretty sure you can make the window bigger than the resolution of the machine running the test.
Not to discourage OP but that particular keyword has never worked for my use cases when i had to use that. I did some js based alternative for that once because of that issue but even than, it didnt take horizontal scrolling into account.
At least one of the “issues” i had with scroll element to view was that it just brings the element into viewport but if the page has a toast/static footer that has higher Z order than anything else, interactions where still failing because that toast was still on top of my element i was trying to scroll into view.
Another “possible” issue was that even without a toast, scrolling the viewport ended if even 1 pixel row of the element was already in the viewport. But about this one I’m not sure if this was the real case or did i try to debug it.
But then again, my memory is faint on these matters as it has been long time since i actually wrote anything with selenium.
I tried to zoom out using Press Keys (CTRL and -) but it actually didn’t work.
I tried to use the set window size to set the size to 1920x1080 but the window was set up to 1040x720 and couldn’t go any higher than that.
Finally the scroll element into view key word is not gonna help as when zoomed in this website hide the elements and make them accessible via others ways like hovering or clicking some other button.
I had to readjust my test to take the view of the smaller resolutions into account.
Yes that will still work. The Selenium Library keywords behave no different in headless mode.
I’ve used headless mode in the past, running scripts in Azure DevOps. The Windows VM of Azure DevOps only supports the 1024 * 768 screen resolution by default, which is very annoying.