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

I have a WebElement, I want to reset its an attribute's value to some other value (for e.g. attr is the attribute, and I want to change its original value=1 to new value=10).

Is it possible? I am using Selenium 2.0 (WebDriver.)

1 Answer

0 votes
by (62.9k points)

You can set any of the attribute value of a web element in selenium. You just need to use the JavascriptExecutor class. It’s used like this:

WebDriver driver; // Assigned elsewhere

JavascriptExecutor js = (JavascriptExecutor) driver;

js.executeScript("document.getElementById('//id of element').setAttribute('attr', '10')");

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 Selenium training

Browse Categories