Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Maximize WebDriver (Selenium 2) in Python.
We can maximize browser window with Selenium webdriver in Python. It is a good practise to maximize the browser while running the tests to reduce the chance of failure.
Once a browser is maximized, the majority of elements become visible to the screen and the probability of interaction with the driver increases. Also, with a maximized browser, users have a better view of the elements on the page.
Some of ways of maximizing browser −
With the maximize_window method
Syntax
driver.maximize_window()
With the fullscreen_window method
Syntax
driver.fullscreen_window()
Example
Code Implementation with maximize_window()
from selenium import webdriver
#set chromedriver.exe path
driver = webdriver.Chrome (executable_path="C:\chromedriver.exe")
# maximize browser
driver.maximize_window()
driver.get("https://www.tutorialspoint.com/index.htm")
driver.close()
Example
Code Implementation with fullscreen_window()
from selenium import webdriver
#set chromedriver.exe path
driver = webdriver.Chrome (executable_path="C:\chromedriver.exe")
# maximize browser
driver.fullscreen_window()
driver.get("https://www.tutorialspoint.com/index.htm")
driver.close()
In the above examples, we have performed the below steps −
The browser driver path has been configured.
The browser has been launched.
URL has been hit on the browser.
The browser has been maximized.
Finally, the browser has been closed.
