I found this for java :-
WebElement html = driver.findElement(By.tagName("html"));
html.sendKeys(Keys.chord(Keys.CONTROL, Keys.ADD));
But how to do this using Python? I want to zoom out one level after get requests.
this does the job for Python with selenium (-v 3.141.0)
driver = webdriver.Chrome(executable_path='...')
driver.get("www.stackoverflow.com")
driver.execute_script("document.body.style.zoom='50%'")
You can do something similar where you specify the zoom levels as below:
For example, if my body has a <div id='values'>, I could zoom the div using
from selenium import webdriver
def main():
browser = webdriver.Chrome()
browser.set_window_size(1000, 1000)
browser.get("http://yoursite.com")
browser.execute_script("$('#values').css('zoom', 5);")
if __name__ == '__main__':
main()
Or Simply try:
driver.execute_script("document.body.style.zoom='zoom %'")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With