简体   繁体   中英

How do I resize a WebDriverJS browser window?

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.

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?

经过一个多星期的混乱搜索api文档和谷歌,答案实际上是在selenium-webdriver测试节点模块的测试文件夹内!

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

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 :

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM