Michael Durrant
Michael Durrant

Reputation: 96484

selenium - how to select a hyperlink in a table based on the displayed name of the hyperlink

I have a table which lists records (school districts in my case).

I want to use Selenium to select the delete icon (the eight td) for the district that is in a row with a certain name, in my case, the name QA__run being in the first td

How can I do that?

I have tried:

//table[@id='districts']//tr//td//a[contains[text(),'QA__run (Selected)']]

and

//table[@id='districts']//tr//td//a[contains[text(),"*QA__run*"]]

but neither selector worked.

So far the best I have is:

//table[@id='districts']//tr//td

to select the first td of the first tr but that's not specific enough

The table looks like: enter image description here

Upvotes: 0

Views: 476

Answers (1)

Yi Zeng
Yi Zeng

Reputation: 32865

You find the td with the text first, then go back to the ancestor tr, get the 8th td in that tr.

//table//tr//td//a[text() ='QA__run']//ancestor::tr//td[8]

Upvotes: 1

Related Questions