How to getText from the disabled input field in selenium webdriver
How to getText from the disabled input field in selenium webdriver it might prove to be a bit tricky if you you are used to get text using the “normal way” locator.text or locator.getText() in java.
You might have a disabled input field that dynamically generates values like the following piece of html:
Your first instinct will be write [code] locator.text in ruby or locator.getText() in java depending of your language and you’ll end up in the situation that your returned result will be null.
The solution for this is to use the html value attribute and you can do it like this :
or in ruby :
This guy basically is going to return you a string and from here you can play with it as long as you want.
The second solution is to get the text using java script executor, something like this :
or in java
This is just a guide that it might or it might not work for you , but as you know html value attribute specifies the value of an <input> element. The value attribute is used differently for different input types: For “button”, “reset”, and “submit” – it defines the text on the button. For “text”, “password”, and “hidden” – it defines the initial (default) value of the input field.
If you find yourself in one of this situation try this solution out and see where it goes.
If you want to know more about element attribute your can read our article How to use : Capybara get attribute .
I hope this article unblocked you and if you have any suggestions for new topics that you want to find answers please do not hesitate to give us a shot.