mikeybaby173
mikeybaby173

Reputation: 1312

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?

Upvotes: 17

Views: 12430

Answers (2)

mikeybaby173
mikeybaby173

Reputation: 1312

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

Upvotes: 36

ChristianB
ChristianB

Reputation: 1977

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

Upvotes: 1

Related Questions