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?
- Use the default keyboard shortcut Ctrl+Shift+A (Command+Shift+A for Mac) to resize to the next window size in your list. Keep using the shortcut to rotate window sizes.
The resizeTo() method is used to resizes a window to the specified width and height.
Protractor allows setting the custom browser window size. Custom width and height can be mentioned in the Set Size function, the browser window will be resized to the mentioned width and height. Purpose: The function setSize() in the Window class is used to resize the browser window.
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);
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With