Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set browser width and height in Selenium WebDriver?

I'm using Selenium WebDriver for Python. I want instantiate the browser with a specific width and height. So far the closest I can get is:

driver = webdriver.Firefox() driver.set_window_size(1080,800) 

Which works, but sets the browser size after it is created, and I want it set at instantiation. I'm guessing there is an approach along the lines of:

profile = webdriver.FirefoxProfile(); profile.set_preference(foo, 1080) driver = webdriver.Firefox(profile) 

But I don't know what foo would be, and I can't figure out where the docs are.

Q1: is there a way to set width / height at instantiation?

Q2: Where are the reference docs listing all keys usable by profile.set_preference?

like image 472
tom Avatar asked Mar 13 '13 22:03

tom


People also ask

How can you set the size of the browser window to the below Dimension?

You need to use resize method to minimize the browser. void setSize() – This method is used to set the size of the current browser. Dimension getSize() – This method is used to get the size of the browser in height and width. It returns the dimension of the browser.

Which of the following is used to set the browser window size to 600 * 400 in Selenium?

With setSize() method.

How do you find width and height in Selenium?

To get the width and height of a rendered web element programmatically using Selenium in Java, use WebElement. getSize() function. We first find the web element by name, id, class name, etc., and then call the getSize() function on this web element. getSize() function returns a Dimension object.

How do I resize Chrome in Selenium?

We can resize the browser window in Selenium webdriver. We can configure the size of the browser with the help of the set_window_size method in Python. The dimensions of the window size are passed as parameters to this method. Again, to get the size of the browser, we can use the method get_window_size.


1 Answers

Here is how I do it in Python with Selenium 2.48.0:

from selenium.webdriver import Firefox driver = Firefox() driver.set_window_position(0, 0) driver.set_window_size(1024, 768) 
like image 117
sirex Avatar answered Sep 30 '22 21:09

sirex