Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using Curly Brackets in xpath – Selenium – Beginner

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Sorry, I am new to this 🙂

Thanks
Pat

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading