I've been messing around with python/selenium a bit, now I got to use the "try" method. I want the driver to wait until it maximized the window, and then go on with the code. At the beginning it just went on executing all scripts and the chrome window got maximized whilst executing it, which looked pretty weird. Anyways I hope you can help me, Have a good day y'all;))
Ah, here's the code: (And the error message beneath it)
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome(executable_path=r'C:\Users\Anyone\Desktop\Python\chromedriver.exe')
print("Automation Started, please hold on.")
driver.get("https://blablabla")
try:
recap = WebDriverWait(driver, 5).until(
EC.WebDriverException(driver.maximize_window())
)
finally:
driver.forward()
And here's the error message:
Traceback (most recent call last):
File "C:/Users/Anyone/PycharmProjects/blebleble/blablabla.py", line 17, in <module>
EC.WebDriverException(driver.maximize_window())
File "C:\Users\Anyone\PycharmProjects\blablabla\venv\lib\site-packages\selenium\webdriver\support\wait.py", line 71, in until
value = method(self._driver)
TypeError: 'WebDriverException' object is not callable
After making driver object use the below code:-
driver.manage().window().maximize();
and remove the try/finally block.
Don't wait for the Selenium driven ChromeDriver initiated google-chrome Browsing Context to open first and then maximize it.
Instead, add the argument start-maximized
and configure the driver, so the Google Chrome Browsing Context opens up maximized using the solution below:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
driver = webdriver.Chrome(options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get("https://blablabla")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.