4
votes

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?

2
That's what zoom actually is, are you talking about resizing Chrome? - Manu
there should be a driver.set_window_size - Madhan
@Madhan , sorry for my inadequate knowledge, what I actually want is to simulate pressing 'ctrl' and 'add' button to get a 200% zoom. - Avanti
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
you just want to do that with selenium? - DRPK

2 Answers

-1
votes

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)
-3
votes
driver.execute_script("document.body.style.zoom='75%'")