This is a really basic question but I couldn’t find an answer anywhere… How do I retrieve the text entered in a text field using webdriver under python? I have tried several text and text() neither works.
>>> driver.get("http://en.wikipedia.org/wiki/Main_Page")
>>> el = driver.find_elements_by_xpath("//input[contains(@name, 'search')]")
>>> el
[<selenium.webdriver.remote.webelement.WebElement object at 0x10d15f6d0>]
>>> el[0].send_keys("orange") # this works
>>> el[0].text
''
>>> el[0].text()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' object is not callable
>>> el[0].get_text()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'WebElement' object has no attribute 'get_text'
Thanks!
As I investigated the search element on the Wikipedia site with firebug it seems to me that the entered text value is stored in the value-attribute. So you have to get this attribute.