I'm interested in executing a number of the advanced "Commands" via the javascript API https://code.google.com/p/selenium/source/browse/javascript/webdriver/command.js
If I start with the base code:
var browser = new webdriver
.Builder()
.usingServer(server.address())
.withCapabilities(webdriver.Capabilities.phantomjs())
.build();
every form of "likely" syntax I've tried to execute has failed. for example:
// does not work
console.log(webdriver.Command('getWindowSize'))
// does not work
console.log(browser.Command('getWindowSize'))
Does anyone know how to execute "get window size", or "set window size" in selenium javascript webdriver?
Selenium webdriver can execute Javascript. After loading a page, you can execute any javascript you want. A webdriver must be installed for selenium to work.
var webdriver = require('selenium-webdriver'); var driver = new webdriver. Builder().
You are probably looking for driver.executeScript
.
Example:
var driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.chrome()).
build();
driver.executeScript('return 2').then(function(return_value) {
console.log('returned ', return_value)
});
This will log 2 to the console.
I also tested this with:
driver.get('http://underscorejs.org/');
driver.executeScript('return _').then(function(return_value) {
console.log('returned ', return_value)
});
... which correctly lists all the methods defined on _, so it appears to work.
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