0

My HTML code looks like:

Table 1: And Table 2

<table id="ContentPlaceHolder_Body0">
    <tbody>
        <tr align="Center">
            <td style="width:250px;">Some Name</td>
        </tr>
    </tbody>
</table>
<table id="ContentPlaceHolder_Body1">
    <tbody>
        <tr align="Center">
            <td style="width:250px;">Some Name</td>
        </tr>
    </tbody>
</table>

When I use //*[contains(text(),'Some Name')] this xpath selects 2 values while I need to select only one value by Text.
I need to use that xpath with Text.
I'm trying to create xpath to get the "Some Name" from Table 2, element locator by using Text.
So I created this Xpath:

//table[@id='ContentPlaceHolder_Body1']//tr//td[@text()='Some Name']

This xpath is not working, need help to create correct xpath.

1
  • Can you share the page you are working with? Commented Apr 15, 2021 at 19:01

2 Answers 2

1

Given your HTML, this XPath works for me

//table[@id='ContentPlaceHolder_Body1']//td[text()='Some Name']

I think the issue with your XPath is that you were using @text() when it should be text().

//table[@id='ContentPlaceHolder_Body1']//tr//td[@text()='Some Name']
                                                ^ remove the @
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much its work for me as well
If this, or any other answer, was useful please upvote it. Once you find the answer to your question, please mark it as accepted so the question isn't left unanswered.
0

You need to just remove the @

//table[@id='ContentPlaceHolder_Body1']//tr//td[text()='Some Name']

1 Comment

Thank you very much its work for me as well

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.