Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 935
Dev Avatar asked Nov 22 '25 15:11

Dev


2 Answers

I just found a solution for my question, below code works

driver.manage().window().setRect({width: 640, height: 480, x, y});
like image 53
Dev Avatar answered Nov 25 '25 04:11

Dev


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/webdriver/interactions/windows/

like image 42
Diego Montania Avatar answered Nov 25 '25 05:11

Diego Montania



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!