简体   繁体   中英

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?

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

In your case can help the following code:

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

Hope it helps you!

有时会发生这种情况,在这种情况下,您可以使用element.getAttribute("innerHTML") ,然后可以处理输出字符串。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM