简体   繁体   English

如何使用 FirefoxOptions() 使用 Selenium/Python 放大/缩小 Firefox

[英]How to zoom in/out in Firefox with Selenium/Python using FirefoxOptions()

I want to maximize the window and zoom out to 0.8.我想最大化 window 并缩小到 0.8。

Here is the code:这是代码:

from selenium import webdriver    
from selenium.webdriver.firefox.options import Options
profile = webdriver.FirefoxProfile()
options = webdriver.FirefoxOptions()
options.add_argument('--start-maximized') # not working
driver = webdriver.Firefox(firefox_profile=profile, options=options, executable_path=r"W:\geckodriver.exe")
driver.execute_script('document.body.style.MozTransform = "scale(0.8)";') # not working

The window is not getting maximized nor zoomed out. window 没有最大化也没有缩小。

I used this instead:我改用这个:

#1st install pyautogui
import pyautogui
pyautogui.hotkey('ctrl', '-') #zooms out to 80%
pyautogui.hotkey('ctrl', '-')

Please try the following to zoom out to 0.8:请尝试以下方法缩小到 0.8:

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

You can use the following code to maximize:您可以使用以下代码最大化:

driver.maximize_window()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM