pythonseleniumkeyboard

Can we Zoom the browser window in python selenium webdriver?


I am trying to ZOOM IN and ZOOM OUT the Chrome( selenium webdriver) only using keyboard. I have tried --

from selenium.webdriver.common.keys import Keys
driver.find_element_by_tag_name("body").send_keys(Keys.CONTROL,Keys.SUBTRACT). 

but it is not working. Need answer in python.


Solution

  • I was just struggling with this. I managed to find something that works for me, hopefully it works for you:

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

    Have 'zoom%' = whatever zoom level you want. (e.g. '67%')