Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (19.7k points)

I have a long string to test and sendKeys() takes too long. When I tried to set the value of the text 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. So I am trying to avoid it.

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

inputField = driver.findElement('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);

1 Answer

0 votes
by (62.9k points)

Using the executeScript method, set the element's value:

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

If you wish to Learn Selenium visit this Selenium Webdriver Tutorial and Selenium web driver Interview Questions by Intellipaat.

If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, check out Intellipaat’s automation testing certification!

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

30.5k questions

32.5k answers


108k users

Browse Categories