Newcomer
Newcomer

Reputation: 503

Xpath to an element with two different contains text

I have the next HTML and i have this xpath to find the "Show":

xpath=//*[@id="Some_id"]/div/table/tbody/tr/td[contains(text (), "Show")] 

and it works, but i need to find "Show" of a particular item, in this matter of a "Main" item, so i need smth like this:

xpath=//*[@id="Some_id"]/div/table/tbody/tr/td[contains(text (), "Show")]/preceding-sibling::td[contains(text (), "Main")] 

but it doesn't work. Thanks

<tr class="even">
                    <td title="Main">
                          <a href="Stuff_1"><strong>Main</strong></a>
                    </td>
                    <td>
                      text/html
                    </td>
                    <td>
                      Another text
                    </td>
                    <td>
                      Some text here
                    </td>
                    <td>
                      No
                    </td>
                    <td>

                          <a href="Stuff_1_a">Show</a>
                    </td>
                  </tr>

Upvotes: 1

Views: 3859

Answers (2)

mmohammad
mmohammad

Reputation: 2792

You want to find "Show" that belong to the "Main" row in the table.

Here is what i would do

xpath=//td[@title='Main']/following-sibling::td[contains(text(), 'Show')]

More on xpath axes: http://www.w3schools.com/xsl/xpath_axes.asp

Upvotes: 1

JRodDynamite
JRodDynamite

Reputation: 12613

You can try this xpath. This will first select a tr element which contains the specific td and then select the required a tag.

"//tr[@class='even' and td[@title='Main']]/a[text()='Show']"

EDIT: This xpath worked for the OP

"//*[@id='Some_id']/div[1]/table/tbody/tr[@class='even']/td/a[contains(text (), 'Show')]"

Upvotes: 3

Related Questions