1

I want to search for example (UK) then click on checkbox that is in the same row

HTML (but tr can increase or decrease)

<tr class="ng-scope table-row-style">
    <td class="ng-binding">US</td>
    <td class="ng-binding">United States</td>
    <td class="btn-td" style="padding: 0;">
        <input type="checkbox" class="ng-pristine ng-untouched ng-valid ng-empty">
    </td>
</tr>
<tr class="ng-scope table-row-style">
    <td class="ng-binding">UK</td>
    <td class="ng-binding">United Kingdom</td>
    <td class="btn-td" style="padding: 0;">
        <input type="checkbox" class="ng-pristine ng-untouched ng-valid ng-empty">
    </td>
</tr>
<tr class="ng-scope table-row-style">
    <td class="ng-binding">IN</td>
    <td class="ng-binding">India</td>
    <td class="btn-td" style="padding: 0;">
        <input type="checkbox" class="ng-pristine ng-untouched ng-valid ng-empty">
    </td>
</tr>

2 Answers 2

1

solved by

IList<IWebElement> tableRow = tableElement.FindElements(By.TagName("tr"));
IList<IWebElement> rowTD;
if (tableRow.Count > 0)
{
    foreach (IWebElement row in tableRow)
    {
        rowTD = row.FindElements(By.TagName("td"));
        if (rowTD[0].Text.Equals("UK"))
            rowTD[2].Click();
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

You can find the parent tr element based on child td containing the desired text and then find the child input element as following:

//tr[.//td[contains(.,'UK')]]//input

The entire Selenium command finding and clicking this element could be

driver.FindElement(By.XPath("//tr[.//td[contains(.,'UK')]]//input")).Click();

2 Comments

dose not work cause input inside another td
My XPath expression is locating a parent tr based on the text and then I'm going from that parent tr to it's child input. The input here is not inside the td containing that text. So, if you presented correct XML and correctly copied my XPath it should work.

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.