Sai Krishnan
Sai Krishnan

Reputation: 11

Selenium XPath for WebTable using parent & sibling

I am trying to automate the web table on the demoqa site https://demoqa.com/webtables where I am aiming to click the edit and delete button for a specific user. Please find the attached screenshot for reference.

Screenshot

I am trying to click the edit and delete button for the user 'Cierra' hence I have created the customize XPath '//div[contains(text(),'[email protected]')]//following::div[text()='Insurance']//following::div//div//span[@title='Edit']'

Trying to click the edit and delete button using the contains text with email '[email protected]' however I see four results even I use the unique username. Could anyone help me with this?

Upvotes: 1

Views: 378

Answers (1)

PDHide
PDHide

Reputation: 19979

(//div[contains(text(),'[email protected]')]//following::div[text()='Insurance']//following::div//div//span[@title='Edit'])[1]

you can enclose the result in bracket and call [1] , to get first one:

But you don't have to over complicate it , just get email then go back to parent and get span under that parent ,:

//div[contains(text(),'[email protected]')]/..//span[@title="Edit"]

if you still want to use fancy xpath locator then use :

//div[contains(text(),'[email protected]')]/following-sibling::div[contains(text(),'Insurance')]/following-sibling::div//span[@title='Edit']

Upvotes: 0

Related Questions