setSize() 无法使用 Javascript 在 selenium 中设置浏览器大小

我正在尝试使用以下 javascript 启动后调整浏览器窗口的大小

driver.get(url);
driver.manage().window().setSize(1200,800);

但是,我收到一个错误

'setSize 不是函数\n'。

有人可以帮我解决这个问题吗,我也试过reSizeTo()


宝慕林4294392
浏览 277回答 3
3回答

慕勒3428872

我刚刚为我的问题找到了解决方案,下面的代码有效driver.manage().window().setRect({width: 640, height: 480, x, y});

元芳怎么了

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/

汪汪一只猫

来自硒文档:https ://www.selenium.dev/selenium/docs/api/javascript/module/selenium-webdriver/lib/webdriver_exports_Window.html它没有方法setSize,你应该setRect改用
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript