'{WebElement}.getAttribute("value") returns 0
I am interacting with an element within a webpage:
<li class="MuiButtonBase-root MuiListItem-root MuiMenuItem-root jss524 MuiMenuItem-gutters jss525 MuiListItem-gutters MuiListItem-divider MuiListItem-button" tabindex="-1" role="menuitem" aria-disabled="false" data-quid="SelectListItem-2" value=“{URL}”>
<div class="jss519">
<div class="jss520">
<div>{TEXT}</div>
</div>
<div class="jss522"></div>
</div>
<span class="MuiTouchRipple-root"></span>
</li>
Within my code, I have this snippet:
System.out.println(x.getAttribute("role"));
System.out.println(x.getAttribute("aria-disabled"));
System.out.println(x.getAttribute("data-quid"));
System.out.println(x.getAttribute("class"));
System.out.println(x.getText());
System.out.println(x.getAttribute("value"));
However, the last line System.out.println(x.getAttribute("value"));
prints out 0 instead of the actual value.
I am using selenium 3.141.59
Solution 1:[1]
You can try using the JavascriptExecutor.
protected String getInputValue(WebElement element) {
String js = "return arguments[0].querySelector('input').value";
JavascriptExecutor js = (JavascriptExecutor) driver;
return js.executeScript(js, element).toString();
}
Ref: Selenium Webdriver get input value which already has value attribute (Java)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | RRIL97 |