【问题标题】:Selenium Python XPATH I am trying to select a drop down from the 3rd column of a table where name is in the 1st columnSelenium Python XPATH 我正在尝试从名称位于第一列的表的第三列中选择一个下拉列表
【发布时间】:2016-02-27 05:30:27
【问题描述】:

我有一个包含一些行和列的表。我想选择名称为“Mobile”的下拉元素。名称在 col1 中,下拉列表在 col3 中 使用 XPATH 我可以找到名称“Mobile”,我需要到达 col3 以便我可以选择下拉元素。 我尝试使用“跟随”轴,但这会突出显示 col3 中的所有下拉元素。我很接近,我只需要获取属于 Name Mobile 的下拉列表。

这是我的 XPATH:

//table[@id="data_configuration_edit_mapping_tab_mappings_ct_mapping_body"]//td//div//span[text()="MOBILE"]//following::td//div//select

这是一些 HTML:

<table id="data_configuration_edit_mapping_tab_mappings_ct_mapping_body" cellspacing="0" style="table-layout: fixed; width: 100%;">
<colgroup>
<tbody>
    <tr class="GJPPK2LBFG" __gwt_subrow="0" __gwt_row="0">
    <tr class="GJPPK2LBEH GJPPK2LBGH" __gwt_subrow="0" __gwt_row="1">
    <td class="GJPPK2LBEG GJPPK2LBGG GJPPK2LBHG">
        <div __gwt_cell="cell-gwt-uid-307" style="outline-style:none;">
            <input type="radio" name="rbCrossRow36"/>
        </div>
    </td>
    <td class="GJPPK2LBEG GJPPK2LBGG">
        <div __gwt_cell="cell-gwt-uid-308" style="outline-style:none;">
            <span 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 GJPPK2LBGG">
        <div __gwt_cell="cell-gwt-uid-309" style="outline-style:none;">
            <select tabindex="-1">
        </div>
    </td>
    <td class="GJPPK2LBEG GJPPK2LBGG GJPPK2LBBH">
        <div __gwt_cell="cell-gwt-uid-310" style="outline-style:none;">
            <input id="data_configuration_edit_mapping_tab_details_cb_phone" type="checkbox"/>
        </div>
    </td>
    </tr>
    <tr class="GJPPK2LBEH" __gwt_subrow="0" __gwt_row="11">
        <td class="GJPPK2LBEG GJPPK2LBFH GJPPK2LBHG">
            <div __gwt_cell="cell-gwt-uid-307" style="outline-style:none;">
                <input type="radio" name="rbCrossRow36"/>
            </div>
        </td>
        <td class="GJPPK2LBEG GJPPK2LBFH">
            <div __gwt_cell="cell-gwt-uid-308" style="outline-style:none;">
                <span title="MOBILE" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">MOBILE</span>
        </div>
        </td>
        <td class="GJPPK2LBEG GJPPK2LBFH">
            <div __gwt_cell="cell-gwt-uid-309" style="outline-style:none;">
                <select tabindex="-1">
            </div>
        </td>
        <td class="GJPPK2LBEG GJPPK2LBFH GJPPK2LBBH">
    </tr>
    <tr class="GJPPK2LBFG" __gwt_subrow="0" __gwt_row="12">
    <td class="GJPPK2LBEG GJPPK2LBGG GJPPK2LBHG">
        <div __gwt_cell="cell-gwt-uid-307" style="outline-style:none;">
            <input type="radio" name="rbCrossRow36"/>
        </div>
    </td>
    <td class="GJPPK2LBEG GJPPK2LBGG">
        <div __gwt_cell="cell-gwt-uid-308" style="outline-style:none;">
            <span 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">  
    <td class="GJPPK2LBEG GJPPK2LBGG GJPPK2LBBH">
    </tr>
    <tr class="GJPPK2LBEH" __gwt_subrow="0" __gwt_row="13">

</tbody>
</table>

谢谢, 里亚兹

【问题讨论】:

    标签: python-2.7 selenium xpath selenium-webdriver


    【解决方案1】:

    啊,我想我已经解决了。我尝试将 td[1] 放在跟随轴之后。它突出显示了名称为“Mobile”的同一行中的 1 个下拉元素

    //table[@id="data_configuration_edit_mapping_tab_mappings_ct_mapping_body"]//td//div//span[text()="MOBILE"]//following::td[1]//div//select
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-25
      • 2023-03-21
      • 1970-01-01
      • 2016-12-21
      • 1970-01-01
      • 2023-03-14
      • 2017-12-16
      • 2017-12-17
      相关资源
      最近更新 更多