javaseleniumselenium-webdriverdisabled-inputdisabled-control

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

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