Selenium Webdriver Get Input Value Which Already Has Value Attribute (java)
Solution 1:
How about removing the value attribute through javascript first before getting the value attribute? It's also a workaround but maybe you'll like that more?
Solution 2:
My further research lead me to a solution with the use of cssSelector.
From the documentation to Selenium WebDriver executeScript(String script, Object... args)
method:
The arguments will be made available to the JavaScript via the "arguments" magic variable, as if the function were called via "Function.apply"
Arguments must be a number, a boolean, a String, WebElement, or a List of any combination of the above.
@param args The arguments to the script. May be empty
Answer :
So we can pass our WebElement element
as one of the arguments of executeScript()
method and then use the argument to search among children of our element
.
protectedStringgetInputValue(WebElement element) {
String js = "return arguments[0].querySelector('input').value";
JavascriptExecutor js = (JavascriptExecutor) driver;
return js.executeScript(js, element).toString();
}
Post a Comment for "Selenium Webdriver Get Input Value Which Already Has Value Attribute (java)"