3

I have a few disabled text field auto-populated with some values based on my previous input. I want to verify whether auto-populated values are as per my previous input. But I am unable to get the value from the text field using .getText() or .getAttribute() as the value is not present in the HTML code.

Below is the HTML code got using inspect element:

<span class="ProductList_Row">
<input type="text" class="ProductList_Price" style="width:97px" ***disabled*** data-validation="mandatory"> == $0

The text is a field is auto-populated with value "100" as per my previous input. But how can I verify whether the auto-populated value is 100 in the disabled text box?

Ratmir Asanov
  • 6,237
  • 5
  • 26
  • 40
Arjun
  • 321
  • 3
  • 9
  • 20
  • Where can be the `auto populated values` found if `the value is not present in the html code`? To retrieve the required attribute value those values need to be present in the DOM. Then only we can use `.getText()` or `.getAttribute()` – undetected Selenium Dec 16 '17 at 12:09

3 Answers3

7

The value attribute stores the content of a tag, does not matter whether it is disabled or not. So, you can do it like this:

driver.findElement(By.id("write_element_id_here")).getAttribute("value");

this will return you the value of the element and then you can proceed with the rest. Hope it helps..

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Kenny Omega
  • 398
  • 2
  • 12
4

In your case can help the following code:

value = driver.findElement(By.className("ProductList_Price")).getAttribute("value");

Hope it helps you!

Ratmir Asanov
  • 6,237
  • 5
  • 26
  • 40
0

It happens sometimes and in such cases, you can use element.getAttribute("innerHTML") and you can then process the output string.

Ratmir Asanov
  • 6,237
  • 5
  • 26
  • 40
Jyothi
  • 28
  • 3