Home > Net >  Compare XPATH text to string
Compare XPATH text to string

Time:12-14

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

CodePudding user response:

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
  • Related