<p>这是一个非常基本的问题,但我在任何地方都找不到答案。。。如何使用python下的webdriver检索在文本字段中输入的文本?我试过几个<code>text</code>和<code>text()</code>都没用。</p>
<pre><code>>>> 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'
</code></pre>
<p>谢谢!</p>