Smita
Smita

Reputation: 11

how to retrieve the text within the label tag using python selenium ? i want to use this text to assert testcase to pass/fail

I have used the below print statements and get_attribute with value or text returns none. print statement with .text returns nothing.

print (driver.find_element_by_xpath("//*[@id='lblSuccessMessage']").get_attribute("value"))
print (driver.find_element_by_xpath("//*[@id='lblSuccessMessage']").text)

<strong>
    <label id="SuccessMessagelabel">Text message goes here.</label>
</strong>

Upvotes: 1

Views: 7332

Answers (1)

Guy
Guy

Reputation: 50899

The id is SuccessMessagelabel, not lblSuccessMessage

print (driver.find_element_by_xpath("//*[@id='SuccessMessagelabel']").text)
# or
print (driver.find_element_by_id("SuccessMessagelabel").text)

Upvotes: 2

Related Questions