Xpath to find comment box in dynamic table

Viewed 14

I am trying to find an xpath for a dynamic table below. It grows depending on the number of comments placed on the page.

For the automated test each page will have a different number of comments.

I need to find the last comment in the table.

I have tried the following xpath but it did not work

"//div[@id='commentsTable']//textarea[position()=last()]"

A screenshot and html of a sample table is below

enter image description here

<div class="content" style="max-height: 100000px;">
        <div id="commentsTable" style="padding-top: 10px;">
    <div class="row">
        <div class="col-3">
            <div>20/09/2022 10:20 AM</div>
        </div>
        <div class="col-7">
            <div>test</div>
        </div>
        <div class="col-2">
            <div>User1</div>
                <em class="fas fa-clipboard-list"></em>
        </div>
    </div>
    <hr>
    <div class="row">
        <div class="col-3">
            <div>20/09/2022 10:20 AM</div>
        </div>
        <div class="col-7">
            <div>test</div>
        </div>
        <div class="col-2">
            <div>User1</div>
                <em class="fas fa-clipboard-list"></em>
        </div>
    </div>
    <hr>
    <div class="row">
        <div class="col-3">
            <div>20/09/2022 10:20 AM</div>
        </div>
        <div class="col-7">
            <div>test</div>
        </div>
        <div class="col-2">
            <div>User1</div>
                <em class="fas fa-clipboard-list"></em>
        </div>
    </div>
    <hr>
    <div class="row">
        <div class="col-3">
            <div>20/09/2022 12:06 PM</div>
        </div>
        <div class="col-7">
            <div>
                <textarea class="editableComment" id="comments-1982" data-id="1982" rows="4" maxlength="995" style="width: 100%; height: 80px; border-color: rgb(233, 236, 239); color: rgb(51, 51, 51);">User2test</textarea>
            </div>
        </div>
        <div class="col-2">
            <div>User2 blank</div>
                <em class="fas fa-clipboard-list"></em>
        </div>
    </div>
    <hr>
    <div class="row">
        <div class="col-3">
            <div>20/09/2022 12:06 PM</div>
        </div>
        <div class="col-7">
            <div>
                <textarea class="editableComment" id="comments-1983" data-id="1983" rows="4" maxlength="995" style="width: 100%; height: 80px; border-color: rgb(233, 236, 239); color: rgb(51, 51, 51);">User2test2</textarea>
            </div>
        </div>
        <div class="col-2">
            <div>User2 blank</div>
                <em class="fas fa-clipboard-list"></em>
        </div>
    </div>
    <hr>
    <div class="row">
        <div class="col-3">
            <div>20/09/2022 12:07 PM</div>
        </div>
        <div class="col-7">
            <div>
                <textarea class="editableComment" id="comments-1984" data-id="1984" rows="4" maxlength="995" style="width: 100%; height: 80px; border-color: rgb(233, 236, 239); color: rgb(51, 51, 51);">User2test3</textarea>
            </div>
        </div>
        <div class="col-2">
            <div>User2 blank</div>
                <em class="fas fa-clipboard-list"></em>
        </div>
    </div>
    <hr>
</div>
            <p><strong>Add a comment to the ched:</strong></p>
            <label class="form-label"><strong>Comment Templates:</strong></label>
<span title="" class="k-widget k-dropdown" unselectable="on" role="listbox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-owns="CommentTemplates_listbox" aria-live="polite" aria-disabled="false" aria-readonly="false" aria-busy="false" aria-activedescendant="fa26f791-6c6f-4a46-8ee8-0b7b651a7c57" style="width: 100%; margin-bottom: 10px;"><span unselectable="on" class="k-dropdown-wrap k-state-default"><span unselectable="on" class="k-input">- Select template -</span><span unselectable="on" class="k-select" aria-label="select"><span class="k-icon k-i-arrow-60-down"></span></span></span><input id="CommentTemplates" name="CommentTemplates" style="width: 100%; margin-bottom: 10px; display: none;" type="text" value="" data-role="dropdownlist"></span><script>kendo.syncReady(function(){jQuery("#CommentTemplates").kendoDropDownList({"change":chedInspection_selectCommentTemplate,"dataTextField":"Description","dataValueField":"Comment","optionLabel":"- Select template -","dataSource":{"transport":{"read":{"url":"/chip/ChedInspection/GetChedCommentTemplates"},"prefix":""},"schema":{"errors":"Errors"}}});});</script>            <br>
            <textarea style="width:100%;height:80px" placeholder="Add a comment and press Enter to save" maxlength="995" id="addInspectionComment" data-chedid="4154"></textarea>
            <label id="inspectionLblCount">Characters entered <b>0</b> out of 995.</label>
    </div>
1 Answers

This worked for me:

"(//div[@id='commentsTable']//textarea)[last()]"

Tested here

Related