0

I want to maximize the window and zoom out to 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.

AppCreator
  • 241
  • 1
  • 2
  • 11

2 Answers2

0

I used this instead:

#1st install pyautogui
import pyautogui
pyautogui.hotkey('ctrl', '-') #zooms out to 80%
pyautogui.hotkey('ctrl', '-')
AppCreator
  • 241
  • 1
  • 2
  • 11
-2

Please try the following to zoom out to 0.8:

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

You can use the following code to maximize:

driver.maximize_window()
Paul Lemarchand
  • 2,068
  • 1
  • 15
  • 27
  • driver.manage().window().maximize() gets the error: AttributeError: 'WebDriver' object has no attribute 'manage' BUT this works "driver.maximize_window()" – AppCreator May 26 '21 at 06:33
  • @TobiasAndersson I edited the answer, please try `driver.maximize_window()` – Paul Lemarchand May 26 '21 at 06:33
  • Yes driver.maximize_window() works but nothing happens with driver.execute_script('document.body.style.MozTransform = "scale(0.8)";') driver.execute_script('document.body.style.MozTransformOrigin = "0 0";') – AppCreator May 26 '21 at 06:35
  • @TobiasAndersson I have updated the answer with a better solution. Please try `driver.execute_script("document.body.style.zoom='80%'")`. – Paul Lemarchand May 26 '21 at 06:41
  • Zoom not working. `driver = webdriver.Firefox(firefox_profile=profile, options=options, executable_path=r"W:\geckodriver.exe") driver.maximize_window() driver.execute_script("document.body.style.zoom='80%'")` – AppCreator May 26 '21 at 07:34