Windows - Using a scale greater than 100% causes the page screenshot to be cropped.
joao-voltarelli opened this issue · 1 comments
Describe the bug
The screenshot does not consider the entire page when using a scale greater than 100% on Windows. This affects the use of computer vision depending on the element's position on the page.
Expected behavior
The expected behavior is that the WebBot screenshot considers the entire browser page.
Steps to Reproduce
- Change Windows settings to use a scale greater than 100%.
- Try to save a screenshot of the browser opened by WebBot.
bot = WebBot()
bot.headless = False
bot.browser = Browser.CHROME
bot.driver_path = ChromeDriverManager().install()
bot.browse("https://botcity.dev")
bot.maximize_window()
bot.save_screenshot("screenshot-125%.png")
bot.wait(3000)
bot.stop_browser()
Possible Solution
A possible solution could be to consider the scale factor in the browser dimensions that are returned by the _get_page_size() method. Something like:
def _get_page_size(self):
"""
Returns the browser current page size.
Returns:
width (int): The current page width.
height (int): The current page height.
"""
if not self._driver:
return self.DEFAULT_DIMENSIONS
width = self.execute_javascript("return window.innerWidth") * 1.25
height = self.execute_javascript("return window.innerHeight") * 1.25
return width, height
My Platform
OS: Windows 11 Home
Python version: 3.11.5
BotCity Framework Web version: 0.8.4
Additional context
This bug initially arose from a report from the Bayer team. They were unable to find an element on the page via computer vision.
When we investigated, we discovered that the page was being cropped, and the element did not appear in the screenshot; they were using a resolution scale of 150%
Solved via #106