Home > database >  Selenium - set_window_size() always returning same sized window irrelevant of dimensions specified
Selenium - set_window_size() always returning same sized window irrelevant of dimensions specified

Time:09-23

I am trying to set window size for Firefox Selenium via Python. However, the window is always being resized to the same size, irrelevant of the dimensions passed as parameters to the set_window_size() function.

Below is the code I am using:

driver=webdriver.Firefox()
driver.get("https://google.com")
time.sleep(5)
driver.set_window_size(480,360)
time.sleep(5)
print(driver.get_window_size())

The outputted print statement always shows {width: 1161, height: 661}

I have updated the geckodriver to the latest version and I'm using Ubuntu 18.04 to run the code via an anaconda environment.

I also tried using the execute_script() function to set the window size via JS but I got the same result.

Can anyone point out what I'm doing wrong and how to fix?

CodePudding user response:

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')
  • Related