from pyvirtualdisplay import Display
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
display = Display(visible=0, size=(800, 600))
display.start()
driver = webdriver.Firefox()
driver.get('http://www.espn.go.com')
driver.implicitly_wait(10)
print driver.find_element_by_class_name("timestamp")
driver.quit()
display.stop()
My result is
<selenium.webdriver.remote.webelement.WebElement (session="7b9bac74-fc4e-436f-ba2b-f723bc1e4abd", element="{e91179d6-990c-463f-b56b-a2a38fabecdb}")>
instead of the time stamp: ex: 3h
It does this for everything, I get that weird session and element code instead of the actual text. Even when I change to another element or try a different website. Also, even when I use print driver.find_element_by_xpath("//*[@class='timestamp']")
What you see printed is the WebElement
object string representation. WebElement
instance is returned when you call any find_element_by_*
method in Python-Selenium.
Instead, you meant to get the text
:
driver.find_element_by_class_name("timestamp").text