field, but it returns an empty ...">

Selenium WD - get disabled input value

I am trying to get the value of the disabled ( disabled="disabled" ) <input> field, but it returns an empty string.

I tried: .Text , GetAttribute("value") , but so far nothing works.

+4
source share
1 answer

If you mark it like this:

 <input disabled="true" id='data'> 

Your code should be -

 WebElement.getAttribute("disabled") 

or

 WebElement.getAttribute("id") 

Make sure your code is correct. If this does not work, write the HTML code that you use.

For this tag -

 <input id="j_idt93:j_idt93" type="text" disabled="disabled" maxlength="2000" value="Pārtraukts"> 

To get the value attribute -

 String value = driver.findElement(By.id("j_idt93:j_idt93")).getAttribute("value"); 

value should be Pārtraukts

Let me know if there are any problems.

If this does not work, you may need to use a javascript executor -

 String value = (String)((JavascriptExecutor) driver).executeScript("Java script query in here to return value",""); 

Your request should be -

 return document.getElementById("j_idt93:j_idt93").getAttribute("value"); 
+12
source

All Articles