Back
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.)
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 elsewhereJavascriptExecutor js = (JavascriptExecutor) driver;js.executeScript("document.getElementById('//id of element').setAttribute('attr', '10')");
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!
1.2k questions
2.7k answers
501 comments
693 users