Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Compare XPATH text to string

I want to assert true/false based on the text under this XPATH is equal to a string.

//div[@class=’message au-board’]

so

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

//div[@class=’message au-board’]/text()

Here is the code I have

el = (By.XPATH, ".//div[@class='message au-board']/text()]")
assert el == "AppleOrangeGrape"

Printing el gives: (‘xpath’, ".//div[@class=’message au-board’]/text()")

In Dev Tools pasting ".//div[@class=’message au-board’]/text()" hilights the exact text I want to compare my string to: AppleOrangeGrape

>Solution :

el = (By.XPATH, ".//div[@class='message au-board']/text()]")

You forgot the function name find_element. Also there seems to be an extra ] in that xpath.

el = find_element(By.XPATH, ".//div[@class='message au-board']").text
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading