'setSize() doesn't work to set browser size in selenium using Javascript
I'm trying to resize browser window after launching with below javascript
driver.get(url);
driver.manage().window().setSize(1200,800);
However, I'm getting an error
'setSize is not a function\n'.
Could someone please help me in resolving the issue, I have tried reSizeTo() as well
Solution 1:[1]
I just found a solution for my question, below code works
driver.manage().window().setRect({width: 640, height: 480, x, y});
Solution 2:[2]
This function in 2022 :
var width = 800;
var height = 600;
driver.manage().window().setRect({x: 0, y: 0, width: width, height: height});
https://www.selenium.dev/documentation/en/webdriver/browser_manipulation/
Solution 3:[3]
From selenium doc: https://www.selenium.dev/selenium/docs/api/javascript/module/selenium-webdriver/lib/webdriver_exports_Window.html
it doesn't have method setSize, you should use setRect instead
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Eugen Sunic |
| Solution 2 | |
| Solution 3 | Quang NGUYEN DANG |
