Get value of an input box using Selenium (Python)

前端 未结 2 842
你的背包
你的背包 2020-11-28 10:06

I am trying to extract the text in an input box,


I started with

相关标签:
2条回答
  • 2020-11-28 10:53

    Use this to get the value of the input element:

    input.get_attribute('value')
    
    0 讨论(0)
  • 2020-11-28 11:02

    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.

    0 讨论(0)
提交回复
热议问题