admin管理员组

文章数量:1334877

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

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

Share Improve this question edited Mar 9, 2020 at 10:57 Sebastian Kaczmarek 8,5154 gold badges24 silver badges43 bronze badges asked Mar 9, 2020 at 10:54 DevDev 1011 silver badge8 bronze badges 3
  • 1 I just found a solution for my question, below code works driver.manage().window().setRect({width: 640, height: 480, x, y}); – Dev Commented Mar 9, 2020 at 11:00
  • then post is as an answer instead of putting it in the ment – EugenSunic Commented Mar 9, 2020 at 11:02
  • I'm sorry, I just added it as answer. Thank you @EugenSunic – Dev Commented Mar 9, 2020 at 11:03
Add a ment  | 

3 Answers 3

Reset to default 7

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

driver.manage().window().setRect({width: 640, height: 480, x, y});

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/

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

本文标签: setSize() doesn39t work to set browser size in selenium using JavascriptStack Overflow