8

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

I have tried: .Text, GetAttribute("value"), but none of this works so far.

2 Answers 2

15

If you tag 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.

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 must be Pārtraukts

If this does not work, you may have to use the JavaScript executor -

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

Your query should be -

return document.getElementById("j_idt93:j_idt93").getAttribute("value");
Sign up to request clarification or add additional context in comments.

1 Comment

HTML code is <input id="j_idt93:j_idt93" type="text" disabled="disabled" maxlength="2000" value="Pārtraukts"> I'm trying to get the value attribute.
0

The only option that worked for me...

WebElement webElement = driver.findElement(By.xpath("*******"));
jsExecutor= (JavascriptExecutor) driver;  
String compareHolder = (String) jsExecutor.executeScript("return arguments[0].value", webElement);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.