0

Not able to get Text from the disabled input field in selenium java. I tried:

element.getAttribute("disabled") ==> it returns True.

element.getText() ==> it returns Null

(String) ((JavascriptExecutor) driver).executeScript("angular.element($('#indirectRate')).text()")==> it returns null too.

Here is the html:

    <input type="text" id="indirectRate" class="form-control 
ng-pristine ng-untouched ng-valid ng-not-empty 
ng-valid-valdr-digits ng-valid-valdr-min ng-valid-valdr-max ng-valid-valdr" 
 name="indirectRate" ng-model="proposal.budget.indirectRate" ng- 
 disabled="proposalElementDisabled() || proposal.budget.indirectType === 
 'DISALLOWED'" disabled="disabled">
Hasan Patel
  • 412
  • 7
  • 19
Yani
  • 11
  • 1
  • 2
    Possible duplicate of [Using Selenium Web Driver to retrieve value of a HTML input](https://stackoverflow.com/questions/7852287/using-selenium-web-driver-to-retrieve-value-of-a-html-input) – JeffC Apr 29 '19 at 18:43
  • 1
    Rather than putting important information in the comments, edit your question and add the HTML (and any other relevant info) there instead. This prevents future readers from having to read all the comments to get all the relevant bits to answer the question. – JeffC Apr 29 '19 at 18:44
  • @Yani There can't be any _text_ as such in an `` tag but there can be _placeholder_ text. Are you trying to extract the _value_ of any attribute? Which _attribute_? – undetected Selenium Apr 29 '19 at 20:36

3 Answers3

0

Use the following:

element.getAttribute("value")

"innerHTML" and "input" texts are handled differently in selenium.

Valga
  • 459
  • 2
  • 7
0

You can try by using value

  1. element.getAttribute("value")

or you can try getting the value over angular element

  1. return (String) ((JavascriptExecutor) this.webDriver).executeScript("angular.element($('#indirectRate')).text()");

You can find more information in this thread: Selenium WD - get value of disabled input

Hasan Patel
  • 412
  • 7
  • 19
0

try

 element.getAttribute("innerHTML");
murali selenium
  • 3,847
  • 2
  • 11
  • 20