3
這是一個非常基本的問題,但我無法在任何地方找到答案...如何檢索在python下使用webdriver在文本字段中輸入的文本?我試過幾個text
和text()
都不行。如何檢索使用webdriver(python)在文本字段中輸入的文本?
>>> 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'
謝謝!
我不知道這是否工作(因爲我無法測試它),但也許嘗試獲取值屬性的內容。在我看來,輸入的文本是在值屬性中。 – tester 2012-02-19 13:02:58
ding ding'el [0] .get_attribute(「value」)'做到了,謝謝!如果您在答覆中回覆,我可以用複選標記接受... – 2012-02-20 00:39:43