F. Rakes F. Rakes - 10 months ago 261
Javascript Question

Set value of input instead of sendKeys() - selenium webdriver nodejs

I have a long string to test and

takes too long. If I try to set the value the program crashes. I know the Selenium sendKeys() is the best way to test the actual user input, but for my application it takes too much time.

Is there a way to set the value right away?

See this quick example:

var webdriver = require('selenium-webdriver');

var driver = new webdriver.Builder().


// find the search input field on google.com
inputField = driver.findElement(webdriver.By.name('q'));

var longstring = "test"; // not really long for the sake of this quick example

// this works but is slow

// no error but no values set
inputField.value = longstring;

// Output: TypeError: Object [object Object] has no method 'setAttributes'

inputField.setAttributes("value", longstring);


Try to set the element's value using the executeScript method:

webdriver.executeScript("document.getElementById('elementID').setAttribute('value', 'new value for element')");