1

I have a table of 6 columns and some rows. For row 1 Col0 has a checkbox. Col 2 has the text "Name" and col 5 has the text "CRM" Row 2 col 2 has the text "Address" and has the text "CRM" Row 7 col 2 has the text "Name" and col 5 has the text "ESCR" The pattern goes on like this with rows of date.

I would like to select the checkbox from col0 where col2 has the text "Name" and col5 has the text "CRM"

How do i do this using XPATH please?

I have a made a start and I can identify the text "CRM" from col5. I need to get the correct row so I need to find "Name" and then go up to the checkbox.

My XPATH is:

//table[@id="data_configuration_variables_ct_fields_body"]/tbody/tr//td/div/span[@title="CRM" and contains(text(), "CRM")]

I would like to include the text "Name" in the XPATH and then include the checkbox. I can then select the correct row.

The HTML sample is (sorry for the long HTML - i don't know how to provide it in a shorter way):

    <table id="data_configuration_variables_ct_fields_body" cellspacing="0" style="table-layout: fixed; width: 100%;">
<colgroup>
<tbody>
    <tr class="GJPPK2LBFG" __gwt_subrow="0" __gwt_row="0">
        <td class="GJPPK2LBEG GJPPK2LBGG GJPPK2LBHG">
            <div __gwt_cell="cell-gwt-uid-1130" style="outline-style:none;" tabindex="0">
                <input type="checkbox" tabindex="-1"/>
            </div>
            </td>
            <td class="GJPPK2LBEG GJPPK2LBGG">
                <div __gwt_cell="cell-gwt-uid-1131" style="outline-style:none;">
                    <span class="linkhover" title="Name" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;color:#00A;cursor:pointer;">Name</span>
                </div>
            </td>
            <td class="GJPPK2LBEG GJPPK2LBGG">
                <div __gwt_cell="cell-gwt-uid-1132" style="outline-style:none;">
                    <span class="" title="Name" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">Name</span>
                </div>
            </td>
            <td class="GJPPK2LBEG GJPPK2LBGG">
                <div __gwt_cell="cell-gwt-uid-1133" style="outline-style:none;">
                    <span class="" title="" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;"/>
                </div>
            </td>
            <td class="GJPPK2LBEG GJPPK2LBGG">
                <div __gwt_cell="cell-gwt-uid-1134" style="outline-style:none;">
                    <span title="CRM" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">CRM</span>
                </div>
            </td>
            <td class="GJPPK2LBEG GJPPK2LBGG GJPPK2LBBH">
            </tr>
            <tr class="GJPPK2LBEH" __gwt_subrow="0" __gwt_row="1">
                <td class="GJPPK2LBEG GJPPK2LBFH GJPPK2LBHG">
                <div __gwt_cell="cell-gwt-uid-1130" style="outline-style:none;">
                    <input type="checkbox" tabindex="-1"/>
                </div>
            </td>
            <td class="GJPPK2LBEG GJPPK2LBFH">
                <div __gwt_cell="cell-gwt-uid-1131" style="outline-style:none;">
                    <span class="linkhover" title="Address" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;color:#00A;cursor:pointer;">Address</span>
                </div>
            </td>
            <td class="GJPPK2LBEG GJPPK2LBFH">
                <div __gwt_cell="cell-gwt-uid-1132" style="outline-style:none;">
                    <span class="" title="Address" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">Address</span>
                </div>
            </td>
            <td class="GJPPK2LBEG GJPPK2LBFH">
                <div __gwt_cell="cell-gwt-uid-1133" style="outline-style:none;">
                    <span class="" title="" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;"/>
                </div>
            </td>
            <td class="GJPPK2LBEG GJPPK2LBFH">
                <div __gwt_cell="cell-gwt-uid-1134" style="outline-style:none;">
                    <span class="" title="CRM" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">CRM</span>
            </div>
            </td>
            <td class="GJPPK2LBEG GJPPK2LBFH GJPPK2LBBH">
            </tr>
            <tr class="GJPPK2LBFG" __gwt_subrow="0" __gwt_row="2">
            <td class="GJPPK2LBEG GJPPK2LBGG GJPPK2LBHG">
                <div __gwt_cell="cell-gwt-uid-1130" style="outline-style:none;">
                    <input type="checkbox" tabindex="-1"/>
                </div>
            </td>
            <td class="GJPPK2LBEG GJPPK2LBGG">
                <div __gwt_cell="cell-gwt-uid-1131" style="outline-style:none;">
                    <span class="linkhover" title="DOB" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;color:#00A;cursor:pointer;">DOB</span>
                </div>
            </td>
            <td class="GJPPK2LBEG GJPPK2LBGG">
                <div __gwt_cell="cell-gwt-uid-1132" style="outline-style:none;">
                    <span class="" title="DOB" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">DOB</span>
                </div>
            </td>
            <td class="GJPPK2LBEG GJPPK2LBGG">
                <div __gwt_cell="cell-gwt-uid-1133" style="outline-style:none;">
                    <span class="" title="" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;"/>
                </div>
            </td>
            <td class="GJPPK2LBEG GJPPK2LBGG">
                <div __gwt_cell="cell-gwt-uid-1134" style="outline-style:none;">
                    <span class="" title="CRM" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">CRM</span>
                </div>
            </td>
            <td class="GJPPK2LBEG GJPPK2LBGG GJPPK2LBBH">
            </tr>
            <tr class="GJPPK2LBEH" __gwt_subrow="0" __gwt_row="3">
            <td class="GJPPK2LBEG GJPPK2LBFH GJPPK2LBHG">
                <div __gwt_cell="cell-gwt-uid-1130" style="outline-style:none;">
                    <input type="checkbox" tabindex="-1"/>
                </div>
            </td>
            <td class="GJPPK2LBEG GJPPK2LBFH">
                <div __gwt_cell="cell-gwt-uid-1131" style="outline-style:none;">
                    <span class="linkhover" title="Phone" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;color:#00A;cursor:pointer;">Phone</span>
                </div>
            </td>
            <td class="GJPPK2LBEG GJPPK2LBFH">
                <div __gwt_cell="cell-gwt-uid-1132" style="outline-style:none;">
                    <span class="" title="Phone" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">Phone</span>
                </div>
            </td>
            <td class="GJPPK2LBEG GJPPK2LBFH">
                <div __gwt_cell="cell-gwt-uid-1133" style="outline-style:none;">
                    <span class="" title="" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;"/>
                </div>
            </td>
            <td class="GJPPK2LBEG GJPPK2LBFH">
            <div __gwt_cell="cell-gwt-uid-1134" style="outline-style:none;">
                <span class="" title="CRM" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">CRM</span>
            </div>
            </td>
            <td class="GJPPK2LBEG GJPPK2LBFH GJPPK2LBBH">
            </tr>
            <tr class="GJPPK2LBFG" __gwt_subrow="0" __gwt_row="4">
            <td class="GJPPK2LBEG GJPPK2LBGG GJPPK2LBHG">
                <div __gwt_cell="cell-gwt-uid-1130" style="outline-style:none;">
                    <input type="checkbox" tabindex="-1"/>
                </div>
            </td>
            <td class="GJPPK2LBEG GJPPK2LBGG">
                <div __gwt_cell="cell-gwt-uid-1131" style="outline-style:none;">
                    <span class="linkhover" title="Email" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;color:#00A;cursor:pointer;">Email</span>
                </div>
            </td>
            <td class="GJPPK2LBEG GJPPK2LBGG">
                <div __gwt_cell="cell-gwt-uid-1132" style="outline-style:none;">
                    <span title="Email" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">Email</span>
                </div>
            </td>
            <td class="GJPPK2LBEG GJPPK2LBGG">
                <div __gwt_cell="cell-gwt-uid-1133" style="outline-style:none;">
                    <span class="" title="" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;"/>
                </div>
            </td>
            <td class="GJPPK2LBEG GJPPK2LBGG">
                <div __gwt_cell="cell-gwt-uid-1134" style="outline-style:none;">
                    <span class="" title="CRM" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">CRM</span>
            </div>
            </td>
            <td class="GJPPK2LBEG GJPPK2LBGG GJPPK2LBBH">
                <div __gwt_cell="cell-gwt-uid-1135" style="outline-style:none;">
                    <span class="" title="DM" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">DM</span>
                </div>
            </td>
            </tr>
            <tr class="GJPPK2LBEH" __gwt_subrow="0" __gwt_row="5">
            <td class="GJPPK2LBEG GJPPK2LBFH GJPPK2LBHG">
                <div __gwt_cell="cell-gwt-uid-1130" style="outline-style:none;">
                    <input type="checkbox" tabindex="-1"/>
                </div>
            </td>
            <td class="GJPPK2LBEG GJPPK2LBFH">
            <div __gwt_cell="cell-gwt-uid-1131" style="outline-style:none;">
                <span class="linkhover" title="ACVSEQ" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;color:#00A;cursor:pointer;">ACVSEQ</span>
            </div>
            </td>
            <td class="GJPPK2LBEG GJPPK2LBFH">
                <div __gwt_cell="cell-gwt-uid-1132" style="outline-style:none;">
                    <span class="" title="ACVSEQ" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">ACVSEQ</span>
                </div>
            </td>
            <td class="GJPPK2LBEG GJPPK2LBFH">
                <div __gwt_cell="cell-gwt-uid-1133" style="outline-style:none;">
                    <span class="" title="" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;"/>
                </div>
            </td>
            <td class="GJPPK2LBEG GJPPK2LBFH">
                <div __gwt_cell="cell-gwt-uid-1134" style="outline-style:none;">
                    <span class="" title="CRM" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">CRM</span>
            </div>
            </td>
            <td class="GJPPK2LBEG GJPPK2LBFH GJPPK2LBBH">
                <div __gwt_cell="cell-gwt-uid-1135" style="outline-style:none;">
                    <span class="" title="DM" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">DM</span>
                </div>
            </td>
            </tr>
            <tr class="GJPPK2LBFG" __gwt_subrow="0" __gwt_row="6">
            <td class="GJPPK2LBEG GJPPK2LBGG GJPPK2LBHG">
                <div __gwt_cell="cell-gwt-uid-1130" style="outline-style:none;">
                    <input type="checkbox" tabindex="-1"/>
                </div>
            </td>
            <td class="GJPPK2LBEG GJPPK2LBGG">
                <div __gwt_cell="cell-gwt-uid-1131" style="outline-style:none;">
                    <span class="linkhover" title="Name" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;color:#00A;cursor:pointer;">Name</span>
                </div>
            </td>
            <td class="GJPPK2LBEG GJPPK2LBGG">
                <div __gwt_cell="cell-gwt-uid-1132" style="outline-style:none;">
                    <span class="" title="Name" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">Name</span>
                </div>
            </td>
            <td class="GJPPK2LBEG GJPPK2LBGG">
                <div __gwt_cell="cell-gwt-uid-1133" style="outline-style:none;">
                    <span class="" title="" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;"/>
                </div>
            </td>
            <td class="GJPPK2LBEG GJPPK2LBGG">
                <div __gwt_cell="cell-gwt-uid-1134" style="outline-style:none;">
                    <span class="" title="ESCR" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">ESCR</span>
                </div>
            </td>
            <td class="GJPPK2LBEG GJPPK2LBGG GJPPK2LBBH">
                <div __gwt_cell="cell-gwt-uid-1135" style="outline-style:none;">
                    <span class="" title="DM" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">DM</span>
                </div>
            </td>
            </tr>
            <tr class="GJPPK2LBEH" __gwt_subrow="0" __gwt_row="7">
            <tr class="GJPPK2LBFG" __gwt_subrow="0" __gwt_row="8">
            <tr class="GJPPK2LBEH" __gwt_subrow="0" __gwt_row="9">
            <tr class="GJPPK2LBFG" __gwt_subrow="0" __gwt_row="10">

</tbody>
</table>

Thanks, Riaz

1 Answer 1

2

Don't overcomplicate things (broke into multiple lines for readability):

//table[@id="data_configuration_variables_ct_fields_body"]
    //tr[td[2]//span = "Name" and td[5]//span = "CRM"]
        /td[1]/div/input

Here we are locating the tr elemen having a span with text Name in the second cell and span with text CRM in the fifth. After getting the appropriate row, we are locating the input element.

No need to go down and up the tree as @BenChand suggested.

Sign up to request clarification or add additional context in comments.

5 Comments

This will work better for me because if i wanted to locate Address with the text ESCR instead of CRM, it could be in any row.
I will be passing in Name as a parameter from my python selenium script. I could pass in Name or Address
Neat, didn't know you could query rows like this without traversing up and down the tree! Thanks
@RiazLadhani yeah, you are missing the opening [. This should be good: //table[@id="data_configuration_variables_ct_fields_body"]//tr[td[2]//span="Name‌​" and td[5]//span="CRM"]/td[1]/div/input
Great, Thanks for you help.

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.