-5

when i am trying to find element using below xpath i'm getting syntax error,so what could be a reason, i'm following this question but it's not working for me

https://stackoverflow.com/a/58400631/12849200

My Xpath:

dp_month = driver.find_element_by_xpath('//*/td[@aria-label='+month_label+']/div[contains(text(),'+ x_month +')]')
selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression //*/td[@area-label=November 2025]/div[contains(text(),NOV)] because of the following error:
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//*/td[@area-label=November 2025]/div[contains(text(),NOV)]' is not a valid XPath expression.
Rookie
  • 1
  • 1
  • 4

1 Answers1

0

If you look at the XPath in the error message, you will probably see what the issue is. Your text isn't surrounded by quotes as is required, e.g.

td[@area-label=November 2025]

should be

td[@area-label="November 2025"]

To fix this, you need to adjust your line of code to

dp_month = driver.find_element_by_xpath('//*/td[@aria-label="'+month_label+'"]/div[contains(text(),"'+ x_month +'")]')
JeffC
  • 22,180
  • 5
  • 32
  • 55