I must be thinking about this wrong.
I want to get the contents of an element, in this case a formfield, on a page that I am accessing with Webdriver/Selenium 2
Here is my broken code:
Element=driver.find_element_by_id(ElementID)
print Element
print Element.text
here is the result:
<selenium.webdriver.remote.webelement.WebElement object at 0x9c2392c>
(Notice the blank line)
I know that element has contents since I just stuffed them in there with the previous command using .sendkeys and I can see them on the actual web page while the script runs.
but I need to get the contents back into data.
What can I do to read this? Preferably in a generic fashion so that I can pull contents from varied types of elements.
I believe prestomanifesto was on the right track. It depends on what kind of element it is. You would need to use
element.get_attribute('value')for input elements andelement.textto return the text node of an element.You could check the WebElement object with
element.tag_nameto find out what kind of element it is and return the appropriate value.This should help you figure out: