7

I'm trying to change the zoom in Chrome programmatically. I tried using Python to do this

driver.execute_script("document.body.style.zoom='zoom %'")

But this makes it zoom in CSS, not Chrome itself. How can I affect Chrome's zoom?

SuperBiasedMan
  • 9,814
  • 10
  • 45
  • 73
Avanti
  • 323
  • 5
  • 14
  • That's what zoom actually is, are you talking about resizing Chrome? – Manu Aug 13 '15 at 12:37
  • there should be a [driver.set_window_size](http://seleniumhq.github.io/selenium/docs/api/py/webdriver_remote/selenium.webdriver.remote.webdriver.html?highlight=size#selenium.webdriver.remote.webdriver.WebDriver.set_window_size) – Madhan Aug 13 '15 at 18:13
  • 2
    @Madhan , sorry for my inadequate knowledge, what I actually want is to simulate pressing 'ctrl' and 'add' button to get a 200% zoom. – Avanti Aug 14 '15 at 06:13
  • Just a thought: wouldn't reducing/increasing the window size have the same effect as chrome's zoom function? It's basically just blowing up / scaling the whole site relative to the window. – masterfloda Oct 31 '17 at 21:33
  • you just want to do that with selenium? – DRPK Oct 31 '17 at 22:07
  • @DRPK, there is a hamburger menu which appears only after zooming in.I want to check that – Avanti Feb 05 '18 at 11:36

2 Answers2

-2

The possible solution is:

html = driver.find_element_by_tag_name("html")
# reduce zoom
html.send_keys(Keys.CONTROL, Keys.SUBTRACT)
# increment zoom
html.send_keys(Keys.CONTROL, Keys.ADD)
-4
driver.execute_script("document.body.style.zoom='75%'")
Bhavin Bhadani
  • 22,224
  • 10
  • 78
  • 108
  • 8
    Unless I'm mistaken, this is exactly what the OP said was not working for them because it makes it zoom in CSS, not in Chrome itself. – josliber Aug 25 '15 at 01:29