[Solved] SyntaxError: Failed to execute ‘evaluate’ on ‘Document’: The string ‘xpath’ is not a valid XPath expression [duplicate]


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 +'")]')

solved SyntaxError: Failed to execute ‘evaluate’ on ‘Document’: The string ‘xpath’ is not a valid XPath expression [duplicate]