Vladimir
Vladimir

Reputation: 5

How to zoom out with Selenium in Python?

I realized that some elements on a web-page are not seen. So I cannot click on it. To get access I need to zoom out the page.

If I use this code

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

the page is successfully zoom out but the information I aimed to reach is stick to the upper part of the page and still unavalable for clickig.

I expected to zoom out my page by pressing a combination of keys Ctrl+'-' with Selenium but failed to get any result. I tried this code

import time
from selenium import webdriver
from selenium.webdriver import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By

with webdriver.Chrome() as browser:
    browser.get('https://some_address/index.html')
    time.sleep(1)
    element=browser.find_element(By.ID, 'some_text')
    actions=ActionChains(browser)
    actions.key_down(Keys.CONTROL,element) \
        .key_down(Keys.SUBTRACT,element).key_up(Keys.SUBTRACT,element) \
        .key_down(Keys.SUBTRACT,element).key_up(Keys.SUBTRACT,element) \
        .key_up(Keys.CONTROL,element).perform()

but zoom out does not work.

Upvotes: 0

Views: 51

Answers (0)

Related Questions