The get_attribute() method is capable of obtaining the value we have entered in an input box. To get the value, we have to pass value as a parameter to the method. First of all, we have to identify the input box with the help of any of the locators like id, class, name, css or xpath.
We can get the value of a HTML input with Selenium webdriver. This is achieved with the help of the getAttribute() method. To retrieve the value of the field with tagname input, we have to pass the value as parameter to the getAttribute() method. Let us consider an html code for a html input.
We can send keyboard input to a textbox on a webpage in Selenium webdriver in Python using the method send_keys. The text to be entered is passed as a parameter to that method. To perform keyboard actions, we can also use the send_keys method and then pass the class Keys.
Use this to get the value of the input element:
input.get_attribute('value')
Note that there's an important difference between the value attribute and the value property.
The simplified explanation is that the value attribute is what's found in the HTML tag and the value property is what you see on the page.
Basically, the value attribute sets the element's initial value, while the value property contains the current value.
You can read more about that here and see an example of the difference here.
If you want the value
attribute, then you should use get_attribute:
input.get_attribute('value')
If you want the value
property, then you should use get_property
input.get_property("value")
Though, according to the docs, get_attribute actually returns the property rather than the attribute, unless the property doesn't exist. get_property will always return the property.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With