I have a webpage where some elements get set on page load. I then need to read some of these elements using Selenium. The problem is that when I read them, all I get is an empty string.
This is a partial image of my website:
I'm trying to obtain the Number field. Here is what the DOM looks like for this element:
<input style="; ; " id="sys_readonly.u_po_coordination.number" value="POI1356285" ng-non-bindable="" readonly="readonly" aria-label="Number">
Here is my JAVA code to get that value:
String num = driver.findElement(By.id("sys_readonly.u_po_coordination.number")).getText();
I've tried using XPath as well. I've also tried getting other elements as well. The result is ALWAYS the same: a blank string...
What am I missing? The elements exist because I can set various elements, but reading ones that should be set are always blank.
Any help would be greatly appreciated. Thanks!
CodePudding user response:
driver.findElement(By.id("sys_readonly.u_po_coordination.number")).getAttribute("value");
Found this website which was pretty useful: https://www.lambdatest.com/blog/how-to-get-text-of-an-element-in-selenium/
CodePudding user response:
Instead of getText() can you try getValue()?