如何调整WebDriverJS浏览器窗口的大小?

时间:2020-11-28 07:17:16

I am using WebDriverJS, the JavaScript bindings for WebDriver, to do some simple frontend testing (driven by nodejs). However, I'm running into difficulties resizing the window, and the documentation is just a bit unclear to me.

我使用WebDriverJS, WebDriver的JavaScript绑定,来做一些简单的前端测试(由nodejs驱动)。但是,我在调整窗口大小时遇到了困难,文档对我来说有点不清楚。

var webdriver = require('selenium-wedriver');

driver = new webdriver.Builder()
           .withCapabilities(webdriver.Capabilities.chrome())
           .build();

driver.get("http://www.google.com")
.then(function() {
    driver.Window.setSize(400, 400);  // <-- should resize, does nothing
})
// more thenables...

Everything works normally and it gives no error, but the browser window does not resize. Am I referencing this setSize method incorrectly?

一切正常,不会出错,但浏览器窗口不会调整大小。是否引用了这个setSize方法?

2 个解决方案

#1


21  

After more than a week of confused searching through the api docs and google, the answer was actually lying inside of the tests folder of the selenium-webdriver tests node module!!

在api文档和谷歌中搜索了一个多星期之后,答案实际上就在selenium-webdriver测试节点模块的测试文件夹中!

driver.manage().window().setSize(x, y);

#2


1  

I don't know how selenium-webdriver works so I can't help you there but just in case you are interested, here is how it works with WebdriverJS:

我不知道selenium-webdriver是如何工作的,所以我不能帮你,但如果你感兴趣的话,下面是它与WebdriverJS的合作方式:

var webdriverjs = require('webdriverjs');
var options = {
    desiredCapabilities: {
        browserName: 'chrome'
    }
};

webdriverjs
    .remote(options)
    .init()
    .windowHandleSize({width:1024,height:768})
    .url('http://www.google.com')
    .title(function(err, res) {
        console.log('Title was: ' + res.value);
    })
    .end();

#1


21  

After more than a week of confused searching through the api docs and google, the answer was actually lying inside of the tests folder of the selenium-webdriver tests node module!!

在api文档和谷歌中搜索了一个多星期之后,答案实际上就在selenium-webdriver测试节点模块的测试文件夹中!

driver.manage().window().setSize(x, y);

#2


1  

I don't know how selenium-webdriver works so I can't help you there but just in case you are interested, here is how it works with WebdriverJS:

我不知道selenium-webdriver是如何工作的,所以我不能帮你,但如果你感兴趣的话,下面是它与WebdriverJS的合作方式:

var webdriverjs = require('webdriverjs');
var options = {
    desiredCapabilities: {
        browserName: 'chrome'
    }
};

webdriverjs
    .remote(options)
    .init()
    .windowHandleSize({width:1024,height:768})
    .url('http://www.google.com')
    .title(function(err, res) {
        console.log('Title was: ' + res.value);
    })
    .end();