8

How can I get text from a disabled input field in Selenium Java?

Below is the HTML tag.

<input id="endDate" class="ng-pristine ng-untouched ng-valid ng-valid-maxlength" data-ng-disabled="dateRange!=='Cm'" size="10" maxlength="10" data-ng-model="endDate" validate-date="" name="endDate" disabled=""/>

I'm looking for Selenium Java code to get the text value from that disabled input field.

I tried getAttribute("disabled"). But it is returning true. I tried WebElement.getAttribute("id"), but it is returning null value. None of it worked.

The value of that field will be generated dynamically. For example, if I select today the values will be populated as SYSDATE. For the yesterday value will be SYSDATE-1.

1

1 Answer 1

11

Try:

webElement.findElement(By.cssSelector("#endDate")).getAttribute("value")

Or:

webElement.findElement(By.cssSelector("#endDate")).getText()

You have to try it out. It depends on your special case. If these variants don't work, check if your selectors are correct.

If all of them didn't work, try to get the value over angular.element as below:

return (String) ((JavascriptExecutor) this.webDriver).executeScript("angular.element($('#endDate')).text()");
Sign up to request clarification or add additional context in comments.

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.