Selenium XPATH我试图从HTML表中找到第2列中的元素,其中文本值在第1列中

时间:2016-10-04 16:18:09

标签: python-2.7 xpath selenium-webdriver

我有一个带有输入值" AREACODE"的HTML表格。在第1列和第2列中有一个select元素(下拉字段)。我试图找到与输入值在同一行的选择元素" AREACODE" 我可以找到值为" AREACODE"的Input元素。 我不知道如何转到同一行的下一列td来获取Select元素。

我的XPATH是:

//table[@id="data_configuration_edit_data_object_tab_details_tb_fields"]/tbody//tr//td//div//input[@value="AREACODE"]/following-sibling/td/div/select

我也尝试过:

//table[@id="data_configuration_edit_data_object_tab_details_tb_fields"]/tbody//tr//td//div//input[@value="AREACODE"]/following-sibling::td/div/select

HTML代码段为:

    <table id="data_configuration_edit_data_object_tab_details_tb_fields" class="GFNQNVHJE border" cellspacing="0" __gwtcellbasedwidgetimpldispatchingfocus="true" __gwtcellbasedwidgetimpldispatchingblur="true">
    <thead aria-hidden="false">
        <colgroup>
            <tbody style="">
                <tr class="GFNQNVHCD GFNQNVHJD" __gwt_subrow="0" __gwt_row="0">
                    <td class="GFNQNVHBD GFNQNVHDD GFNQNVHED GFNQNVHKD">
                        <td class="GFNQNVHBD GFNQNVHDD GFNQNVHKD">
                            <div __gwt_cell="cell-gwt-uid-319" style="outline-style:none;">
                                <input id="" type="text" style="color: black;" value="AREACODE"/>
                            </div>
                        </td>
                        <td class="GFNQNVHBD GFNQNVHDD GFNQNVHKD">
                            <div __gwt_cell="cell-gwt-uid-320" style="outline-style:none;">
                                <select tabindex="-1">
                                    <option value="Integer">Integer</option>
                                    <option selected="selected" value="Text string">Text string</option>
                                    <option value="Date/time">Date/time</option>
                                    <option value="Floating point">Floating point</option>
                                </select>
                            </div>
                        </td>
                        <td class="GFNQNVHBD GFNQNVHDD GFNQNVHOD GFNQNVHKD">
                        </tr>
                        <tr class="GFNQNVHCE" __gwt_subrow="0" __gwt_row="1">
                            <tr class="GFNQNVHCD" __gwt_subrow="0" __gwt_row="2">
                            </tbody>
                            <tbody style="display: none;">
                                <tfoot style="display: none;" aria-hidden="true"/>
</table>

获取输入元素的值=&#34; AREACODE&#34; XPATH是:

//table[@id="data_configuration_edit_data_object_tab_details_tb_fields"]/tbody//tr//td//div//input[@value="AREACODE"]

现在我如何进入select元素所在的下一列?

请问正确的XPATH是什么? 谢谢,Riaz

2 个答案:

答案 0 :(得分:1)

试试这个xpath

"//table[@id='data_configuration_edit_data_object_tab_details_tb_fields']//td/div/input[@value='AREACODE']/../../following-sibling::td[1]/div/select"

答案 1 :(得分:1)

您应该尝试使用以下xpath: -

.//table[@id='data_configuration_edit_data_object_tab_details_tb_fields']//tr[descendant::input[@value='AREACODE']]//select

或使用following-sibling轴作为: -

.//table[@id='data_configuration_edit_data_object_tab_details_tb_fields']//tr//td[div/input[@value='AREACODE']]/following-sibling::td//select