Riaz Ladhani
Riaz Ladhani

Reputation: 4062

Selenium XPATH I am trying to locate an element from column 2 from a HTML table where text value is in column 1

I have a HTML table with an input value "AREACODE" in column 1 and column 2 has a select element (a drop down field). I am trying to locate the select element which is in the same row as the input value "AREACODE" I can locate the Input element which has the value "AREACODE" I am not sure how to go to the next column td in the same row to get to the Select element.

My XPATH is:

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

I have also tried:

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

The HTML snippet is:

    <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>

To get the input element where Value = "AREACODE" the XPATH is:

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

Now how do i go to the next column where the select element is?

What is the correct XPATH please? Thanks, Riaz

Upvotes: 0

Views: 623

Answers (2)

Saurabh Gaur
Saurabh Gaur

Reputation: 23805

You should try using below xpath :-

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

Or using following-sibling Axes as :-

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

Upvotes: 1

Grasshopper
Grasshopper

Reputation: 9058

Try this xpath

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

Upvotes: 1

Related Questions