Compare XPATH text to string

Question:

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

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

so

//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()" highlights the exact text I want to compare my string to: AppleOrangeGrape

Asked By: Nerfed

||

Answers:

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 = driver.find_element(By.XPATH, ".//div[@class='message au-board']").text
Answered By: John Gordon
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.