This should be easy, but I can't get it to work. I'm running a little demo using the Google homepage as a test.
Here's my script:
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
import time
browser = webdriver.Chrome()
browser.get("http://www.google.com") # Load page
time.sleep(0.2)
#top nav elements
elems = browser.find_elements_by_xpath("//span[contains(@class, 'gbts')]")
for e in elems:
print e.get_attribute('text')
browser.close()
It returns:
None
None
None
None
None
None
None
None
None
None
None
So I think it's grabbing the right elements, but perhaps not the right attribute? Not sure. I also tried to print e.text() but that spit out:
Traceback (most recent call last):
File "sample.py", line 14, in <module>
print e.text()
TypeError: 'unicode' object is not callable
Any thoughts?
*Edit - Possible Solution? *
e.get_attribute('innerHTML') seems to work.