'How to get value from a disabled text field when the value is not present in ID or in any attribute using Java in Selenium WebDriver

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?



Solution 1:[1]

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..

Solution 2:[2]

In your case can help the following code:

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

Hope it helps you!

Solution 3:[3]

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

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 undetected Selenium
Solution 2 Ratmir Asanov
Solution 3 Ratmir Asanov