![](/img/trans.png)
[英]how to get updated hidden field value using Selenium webdriver in java
[英]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
我有一些禁用的文本字段,這些文本字段根據我先前的輸入自動填充了一些值。 我想驗證自動填充的值是否與我之前的輸入一致。 但是我無法使用.getText()
或.getAttribute()
從文本字段獲取值,因為HTML代碼中不存在該值。
以下是使用inspect元素獲取的HTML代碼:
<span class="ProductList_Row">
<input type="text" class="ProductList_Price" style="width:97px" ***disabled*** data-validation="mandatory"> == $0
根據我之前的輸入,該文本是一個字段,該字段自動填充為值“ 100”。 但是,如何在禁用的文本框中驗證自動填充的值是否為100?
value屬性存儲標簽的內容,無論是否禁用標簽都無關緊要。 因此,您可以這樣做:
driver.findElement(By.id("write_element_id_here")).getAttribute("value");
這將返回元素的值,然后您可以繼續進行其余的操作。 希望能幫助到你..
您的情況可以幫助以下代碼:
value = driver.findElement(By.className("ProductList_Price")).getAttribute("value");
希望對您有幫助!
有時會發生這種情況,在這種情況下,您可以使用element.getAttribute("innerHTML")
,然后可以處理輸出字符串。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.