How to set browser width and height in Selenium WebDriver?
Found a solution:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("window-size=1600,900")
options.add_argument("window-position=2230,0")
browser = webdriver.Chrome(options=options)
related info found here: How to set window size in Selenium Chrome Python
What is the difference between setting window size using Options and setting window size using set_window_size method
Setting the driver window size withdriver.set_window_size(1920, 1080)
and doing that with the use of Options
options.add_argument("window-size=1920,1080")
Seems to be the same.
It's likedriver.get(url)
Anddriver.navigate().to(url)
WebDriver methods that are doing exactly the same thing and actually are synonyms.
The only difference I can notice between setting the driver window size bydriver.set_window_size(1920, 1080)
vs options.add_argument("window-size=1920,1080")
Is that setting / changing the driver window size bydriver.set_window_size(1920, 1080)
can be performed anywhere in your code, even several times, while setting the driver window size withoptions.add_argument("window-size=1920,1080")
Can be performed only once, before creating the driver instance withdriver = webdriver.Chrome(chrome_options=options, executable_path=the_path
)
Selenium - set_window_size() always returning same sized window irrelevant of dimensions specified
Try to set
driver.set_window_position(0,0)
before setting
driver.set_window_size(x, y)
Or try setting
driver.set_window_size(x, y, windowHandle='current')
- Refer: WebDriver API
How do I resize the window in Chrome and Firefox when testing with Selenium?
For Chromejust add before "webdriver.Chrome" init:
chrome_options.add_argument("--window-size=1920x1080")
For all browsers:
There is an official selenium python binding for that:
http://selenium.googlecode.com/git/docs/api/py/webdriver_remote/selenium.webdriver.remote.webdriver.html#selenium.webdriver.remote.webdriver.WebDriver.set_window_size
driver.set_window_size(1920, 1080)
or
driver.maximize_window()
or with javascript
driver.execute_script("window.resizeTo(1920,1080)")
How to Maximize window in chrome using webDriver (python)
You could use ChromeOptions and set suitable argument:
options = ChromeOptions()
options.add_argument("--start-maximized")
driver = ChromeDriver(options)
Related Topics
How to Flatten Lists Without Splitting Strings
Reactornotrestartable Error in While Loop with Scrapy
How to Set a Default Parameter Equal to Another Parameter Value
Change the Colors Within Certain Range to Another Color Using Opencv
Naming Conflict with Built-In Function
Bin Elements Per Row - Vectorized 2D Bincount for Numpy
Changing Iteration Variable Inside for Loop in Python
Running a Process in Pythonw with Popen Without a Console
Force Numpy Ndarray to Take Ownership of Its Memory in Cython
Board-Drawing Code to Move an Oval
Pytz Localize VS Datetime Replace
Accessing Every 1St Element of Pandas Dataframe Column Containing Lists
Python Regular Expressions - How to Capture Multiple Groups from a Wildcard Expression
What Is the Best (Idiomatic) Way to Check the Type of a Python Variable
How to Evaluate the Sum of Values Within Array Blocks
Pyspark: Split Multiple Array Columns into Rows