17

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?

2 Answers 2

36

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!!

driver.manage().window().setSize(x, y);
1
  • 21
    as of May 2018 it's now driver.manage().window().setRect({width: 640, height: 480, x, y}); May 21, 2018 at 23:42
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:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.