Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the value of disabled input using Selenium WebDriver

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.

like image 793
andree Avatar asked Jul 11 '12 09:07

andree


People also ask

How do I know if a Webelement is disabled?

isEnabled() To verify if an element is enabled or disabled on web-page. Returns "ture" if element is enabled and returns "false" if an element is disabled. Examples: Mostly used with button elements, locked/disabled text input elements.

How do you find the value of an element in Selenium?

To get the text entered into an input element, use element. getAttribute("value") where element is the input element. The attribute text is used to get the text from the tags within an element.


1 Answers

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");
like image 119
Hari Reddy Avatar answered Sep 21 '22 15:09

Hari Reddy