这是一个非常基本的问题,但我在任何地方都找不到答案。。。如何使用python下的webdriver检索在文本字段中输入的文本?我试过几个text
和text()
都没用。
>>> 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'
谢谢!
当我使用firebug调查Wikipedia站点上的search元素时,在我看来,输入的文本值存储在value属性中。所以你必须得到这个属性。
因为我一直只使用属性操作。对我来说很好。使用下面的代码。哪些文本需要从输入中获取
相关问题 更多 >
编程相关推荐