Selenium XPATH如何从名称位于第2列并在第4列中命名的表中选择复选框

时间:2016-04-11 11:17:25

标签: python-2.7 xpath selenium-webdriver

我有一个包含一些行和列的HTML表。我想选择复选框,其中有文字"名称"在第2栏文字" crm"在第4栏

示例HTML是:

<table id="data_configuration_mappings_ct_fields_body" cellspacing="0" style="table-layout: fixed; width: 100%;">
<colgroup>
<tbody>
<tr class="GJPPK2LBFG GJPPK2LBMG GJPPK2LBPG" __gwt_subrow="0" __gwt_row="0">
    <td class="GJPPK2LBEG GJPPK2LBGG GJPPK2LBHG GJPPK2LBNG GJPPK2LBAH">
        <div __gwt_cell="cell-gwt-uid-388" style="outline-style:none;">
            <input type="checkbox" tabindex="-1"/>
        </div>
    </td>
    <td class="GJPPK2LBEG GJPPK2LBGG GJPPK2LBNG GJPPK2LBOG GJPPK2LBAH">
        <div __gwt_cell="cell-gwt-uid-389" style="outline-style:none;" tabindex="0">
            <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 GJPPK2LBNG GJPPK2LBAH">
        <div __gwt_cell="cell-gwt-uid-390" 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 GJPPK2LBNG GJPPK2LBAH">
        <div __gwt_cell="cell-gwt-uid-391" 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 GJPPK2LBNG GJPPK2LBAH">
        <div __gwt_cell="cell-gwt-uid-392" style="outline-style:none;">
            <span class="" title="Main"
                  style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">Main</span>
        </div>
    </td>
    <td class="GJPPK2LBEG GJPPK2LBGG GJPPK2LBNG GJPPK2LBAH">
        <div __gwt_cell="cell-gwt-uid-393" style="outline-style:none;">
            <span class="" title="TITLE + FNAME + SNAME + GENDER"
                  style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">TITLE + FNAME + SNAME + GENDER</span>
        </div>
    </td>
    <td class="GJPPK2LBEG GJPPK2LBGG GJPPK2LBNG GJPPK2LBAH">
        <div __gwt_cell="cell-gwt-uid-394" 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 GJPPK2LBNG GJPPK2LBAH">
        <div __gwt_cell="cell-gwt-uid-395" 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>
    <td class="GJPPK2LBEG GJPPK2LBGG GJPPK2LBBH GJPPK2LBNG GJPPK2LBAH">
        <div __gwt_cell="cell-gwt-uid-396" 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>
</tr>
<tr class="GJPPK2LBEH" __gwt_subrow="0" __gwt_row="1">
<tr class="GJPPK2LBFG" __gwt_subrow="0" __gwt_row="2">
<tr class="GJPPK2LBEH" __gwt_subrow="0" __gwt_row="3">
<tr class="GJPPK2LBFG" __gwt_subrow="0" __gwt_row="4">
<tr class="GJPPK2LBEH" __gwt_subrow="0" __gwt_row="5">
<tr class="GJPPK2LBFG" __gwt_subrow="0" __gwt_row="6">
    <td class="GJPPK2LBEG GJPPK2LBGG GJPPK2LBHG">
        <div __gwt_cell="cell-gwt-uid-388" style="outline-style:none;">
            <input type="checkbox" tabindex="-1"/>
        </div>
    </td>
    <td class="GJPPK2LBEG GJPPK2LBGG">
        <div __gwt_cell="cell-gwt-uid-389" 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-390" 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-391" style="outline-style:none;">
            <span class="" title="crm2"
                  style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">crm2</span>
        </div>
    </td>
    <td class="GJPPK2LBEG GJPPK2LBGG">
        <div __gwt_cell="cell-gwt-uid-392" style="outline-style:none;">
            <span class="" title="Main"
                  style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">Main</span>
        </div>
    </td>
    <td class="GJPPK2LBEG GJPPK2LBGG">
        <div __gwt_cell="cell-gwt-uid-393" style="outline-style:none;">
            <span class="" title="TITLE + FNAME + SNAME"
                  style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">TITLE + FNAME + SNAME</span>
        </div>
    </td>
    <td class="GJPPK2LBEG GJPPK2LBGG">
        <div __gwt_cell="cell-gwt-uid-394" 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">
        <div __gwt_cell="cell-gwt-uid-395" 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>
    <td class="GJPPK2LBEG GJPPK2LBGG GJPPK2LBBH">
</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">
<tr class="GJPPK2LBEH" __gwt_subrow="0" __gwt_row="11">
<tr class="GJPPK2LBFG" __gwt_subrow="0" __gwt_row="12">
<tr class="GJPPK2LBEH" __gwt_subrow="0" __gwt_row="13">
</tbody>

首先,我可以使用以下Xpath在Firefox中的Xpath检查器中突出显示第2列:

//table[@id="data_configuration_mappings_ct_fields_body"]//tr//td[2]

我不知道如何继续并从第2列获取文本名称,从第4列获取文本crm

我可以使用以下XPath从第1列获取文本名称。我如何还包括第4列的文本crm?

//table[@id="data_configuration_mappings_ct_fields_body"]//tr//td[2]//span[text()="Name"]

我需要一些帮助。

谢谢Riaz

0 个答案:

没有答案