Here is my HTML and trying to get the text must be unique. with Python 2.7
Tried to use:
driver.find_element_by_xpath("//span[@id='lblError']/text()")
The xpath was not valid one.
Here is my HTML and trying to get the text must be unique. with Python 2.7
Tried to use:
driver.find_element_by_xpath("//span[@id='lblError']/text()")
The xpath was not valid one.
try to find the element by ID then get_attribute("innerHTML").
var el = driver.find_element_by_id("lblerror")
var text = el.get_attribute("innerHTML")
To retrieve the text must be unique you can use the execute_script()
method and you can use the following solution:
myElement = driver.find_element_by_xpath("//span[@id='lblError']")
myText = driver.execute_script('return arguments[0].lastChild.textContent;', myElement).strip()
enter code here
time.sleep(1)
enter code here
element = driver.find_element_by_xpath("//span[@id='lblError']")
enter code here
text = element.text