0 votes
1 view
in DevOps and Agile by (19.8k 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 (63.4k 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')");

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


Categories

...