How correct scaling the page with Python + Selenium?

Viewed 161

I am starting learn automation with python + selenium and I have the problem: When I use any of this scripts:

self.driver.execute_script("document.body.style.transform = 'scale(0.8)'") or self.driver.send_keys(Keys.CONTROL, Keys.SUBTRACT) or webdriver.ActionChains(driver=webdriver.Chrome()).key_down(Keys.CONTROL).send_keys("-").perform()

my test site is scaling incorrectly - the scale does not decrease, but the page with empty borders along the edges just moves away and the layout crasheds (last script doesnt work and doesnt stopped with error). Give me the best way for this case, please.
P.S. Method by browser settings:

driver.get('chrome://settings/') driver.execute_script('chrome.settingsPrivate.setDefaultZoom(0.8)') driver.get("https://www.stackoverflow.com/")

works wery well, but in this case Selinium doesnt works corretly with all pages - it can't to choose a locators..

1 Answers

Instead of scaling the page by zooming out, you could try resizing the browser window to larger dimensions. For example, add the following to your Chrome options:

options.add_argument("--window-size=1920,1080")
Related