Here is my code:
print browser.find_element_by_xpath('/html/body/div[2]/div/div/div/h1/div/small')
It prints <selenium.webdriver.remote.webelement.WebElement object at 0x02915310>
but I want it to print the actual value, which would be 0.00
Any ideas?
This should work for you for inner text:
print browser.find_element_by_xpath('/html/body/div[2]/div/div/div/h1/div/small').text
Alternatively, if you're trying to get the value:
print browser.find_element_by_xpath('/html/body/div[2]/div/div/div/h1/div/small').get_attribute("value");
When you find an element you don't find the text of the element, but actually much more. It is a WebElement python object, which has a bunch of useful actions and values associated with it.
So the text of a the element is found by calling the text property is what you a currently looking for
browser.find_element_by_xpath('/html/body/div[2]/div/div/div/h1/div/small')
we get the WebElement with browser.find_element_by_xpath('/html/body/div[2]/div/div/div/h1/div/small')
but for the text we use browser.find_element_by_xpath('/html/body/div[2]/div/div/div/h1/div/small').text
and i am guessing you are going to want work with that as a float value, so ten its float(browser.find_element_by_xpath('/html/body/div[2]/div/div/div/h1/div/small').text)
But there is much more you can look in a WebElement for other WebElements, for like
foo = browser.find_element_by_xpath('/html/body/p')
bar = foo.find_element_by_xpath('/input')
baz = foo.find_element_by_xpath('button')
you can do things like bar.get_attribute('name') which will return a string or bar.send_keys('good stuff') or baz.click()
The documents can be found here
http://selenium-python.readthedocs.org/en/latest/api.html#module-selenium.webdriver.remote.webelement
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With