How to select a xpath based on a a sibling number

39 Views Asked by At

I have a table where i want to select a detail field based on the name. For example i want to select a detail field based of the first John in the table (that is row 29).

username coll: usercard-table/div/div/div[2]///div[1]/div/div[2]/div/div[29]/div/div[3]/div/ details: usercard-table/div/div/div[2]///div[2]/div[2]/div/div[29]/div/div[3]/div/

How can i select the 29th row of the detail field based on a Name?

I have tried to use something like //div[2]/div/div[contains(.,'John)[1]]/div/div[3]/div

Hi for helping out. Hereby a simple example of the code. I want to select the div with the class="cell-icons-after-text based on the 2e John (div\div\div[3])

<div>
    <div>
        <div>

            </span>
                <span name="indicators" class="cell-icons-after-text">
                </span>
                <span name="value" class="cellText">
                    <span class="ui-grid-cell-contents-value"><span name="data">John</span></span>
                </span>
            </span>
        </div>
        <div>

            </span>
                <span name="indicators" class="cell-icons-after-text">
                </span>
                <span name="value" class="cellText">
                    <span class="ui-grid-cell-contents-value"><span name="data">Will</span></span>
                </span>
            </span>
        </div>
        <div>

            </span>
                <span name="indicators" class="cell-icons-after-text">
                </span>
                <span name="value" class="cellText">
                    <span class="ui-grid-cell-contents-value"><span name="data">John</span></span>
                </span>
            </span>
        </div>
    </div>
    <div>
        <div>

            </span>
                <span name="indicators" class="cell-icons-after-text">
                </span>
                <span name="value" class="cellText">
                    <span class="ui-grid-cell-contents-value"><span name="data">John</span></span>
                </span>
            </span>
        </div>
        <div>

            </span>
                <span name="indicators" class="cell-icons-after-text">
                </span>
                <span name="value" class="cellText">
                    <span class="ui-grid-cell-contents-value"><span name="data">Will</span></span>
                </span>
            </span>
        </div>
        <div>
            </span>
                <span name="indicators" class="cell-icons-after-text">
                </span>
                <span name="value" class="cellText">
                    <span class="ui-grid-cell-contents-value"></span>
                </span>
            </span>
        <div>
            </span>
                <span name="indicators" class="cell-icons-after-text">
                </span>
                <span name="value" class="cellText">
                    <span class="ui-grid-cell-contents-value"></span>
                </span>
            </span>
        <div>
            </span>
                <span name="indicators" class="cell-icons-after-text">
                </span>
                <span name="value" class="cellText">
                    <span class="ui-grid-cell-contents-value"></span>
                </span>
            </span>
        </div>
    </div>
</div>

1

There are 1 best solutions below

0
Raven On

Do you have a simple html example code? You can try wildcars: //*[contains(text(),'John')] (i add the second quote missing in your example) And if you have 29 elements that you can non distingate, so: (//*[contains(text(),'John')])[29]