I am using Selenium and want to identify an element via xpath. The locator I want to use looks like this:
ref_code = driver.find_elements_by_xpath("//tr[@data-eui-handler="{ event:'click',handler: 'eui.app.controller.search_results.selectRow' }"]/td[1]")
This ends in a syntax error because as far as I see "event" and "handler" in the string are key words. How can I change it, so it is all seen as a string?
I believe the curly brackets are ending the string format right?
Sorry, I am new to this :)
Thanks Pat
CodePudding user response:
The issue is not the brackets but the "
Use
ref_code = driver.find_elements_by_xpath("//tr[@data-eui-handler=\"event:'click',handler:'eui.app.controller.search_results.selectRow'}\"]/td[1]")
You need to put an \
before "
if they are part of the string