簡體   English   中英

第一次成功迭代后函數崩潰(元素未附加到頁面文檔中)

[英]Functions crashes after first successful iteration (element is not attached to the page document)

想問一下下面的函數有什么問題,第一次迭代沒有任何問題,但是在刷新網格后,當量角器試圖移動到下一個單元格時,它給出了以下錯誤消息:

失敗:舊元素引用:元素未附加到頁面文檔

這樣做的想法是讀取第5列(如果考慮從0開始則為第4列),檢查包含值“ true”的每一行,如果包含true,則執行編輯該行,單擊復選框並保存的操作(所有操作均在該行中執行)每個元素都有一個與狀態代碼相關的唯一ID,因此為什么我在函數中“不使用行”(只是從行中獲取文本,然后作為字符串傳遞來完成ID)元素)

**每次更改和保存值時,表都會刷新

    function resetGoodItemStatus(siteToResetValues){
      var cellsConform = element.all(by.css('#datatableDir tr td:nth-of-type(5)'));
      var conformCounter = 0;
      selectValueDropDown(siteToResetValues)
        cellsConform.each((eachCell) => {
            eachCell.getText().then((cellText) => {
                switch (cellText)
                {
                    case 'true':
                        element(by.id(conformCounter+'-1')).getText().then(function(value){
                            element(by.id('btnEdit-US.'+value)).click();
                            element(by.xpath("//*[@editable-checkbox=\"scopeValue.getConformMapping(scopeValue.getDataRow("+'\'US.'+value+"\')).conform\"]/../span/span/input")).click();
                            element(by.id('btnSubmit-US.'+value)).click();
                        })
                    default:
                        browser.sleep(100)
                }
                conformCounter += 1
                });

        });
      }

編輯該行之前的HTML:

 <tr role="row" class="odd">
 <td id="0-0" class="ng-scope">
<form editable-form="" name="scopeValue.rowforms['US.DAM']" onaftersave="scopeValue.saveData('US.DAM',0)" ng-show="scopeValue.rowforms['US.DAM'].$visible" class="form-buttons form-inline ng-pristine ng-valid ng-hide" style="">
    <button type="button" class="btn btn-xs btn-trans kni kni-check-circle text-info" id="btnSubmit-US.DAM" ng-disabled="scopeValue.rowforms['US.DAM'].$waiting" ng-click="scopeValue.rowforms['US.DAM'].$submit()">
    </button>
    <button type="button" class="btn btn-link kni kni-x-circle-slim" ng-disabled="scopeValue.rowforms['US.DAM'].$waiting" id="btnCancel-US.DAM" ng-click="scopeValue.cancelData('US.DAM',0)">
    </button>
</form>
<div class="buttons" ng-show="!scopeValue.rowforms['US.DAM'].$visible">
    <button type="button" class="btn btn-xs btn-trans kni kni-edit-circle text-info" ng-click="scopeValue.rowforms['US.DAM'].$show()" id="btnEdit-US.DAM">
    </button>
</div></td>
<td id="0-1" class="ng-scope sorting_1">DAM</td>
<td id="0-2" class="ng-scope">US.DAM</td>
<td id="0-3" class="ng-scope">Generic Damaged Code</td>
<td id="0-4" class="ng-scope">
<span editable-checkbox="scopeValue.getConformMapping(scopeValue.getDataRow('US.DAM')).conform" e-name="conform" e-form="scopeValue.rowforms['US.DAM']" e-required="" class="ng-scope ng-binding editable">false</span>
</td></tr>

單擊“編輯”按鈕后的HTML:

<td id="0-4" class="ng-scope">
<span editable-checkbox="scopeValue.getConformMapping(scopeValue.getDataRow('US.DAM')).conform" e-name="conform" e-form="scopeValue.rowforms['US.DAM']" e-required="" class="ng-scope ng-binding editable editable-hide">false</span>
<span class="editable-wrap editable-checkbox ng-scope">
    <span class="editable-controls"><input type="checkbox" name="conform" required="required" class="editable-input ng-pristine ng-empty ng-invalid ng-invalid-required ng-touched" ng-model="$data" style="">
        <div class="editable-error ng-binding ng-hide" ng-show="$error" ng-bind="$error" style=""></div>
    </span>
</span>
</td>

感謝您的時間!

一種簡單的方法是將第5列中所有單元格的文本放入文本數組,然后迭代該文本數組,數組索引等效於表行索引。

一旦單元格文本等於true ,請使用行索引查找表行。 其余元素可以在表格行中找到。

因為在每次迭代中,下面的代碼將再次從頁面中查找所有表行,所以不應發生Stale Exception

function resetGoodItemStatus(siteToResetValues){
    var cellsConform = element.all(by.css('#datatableDir tr td:nth-of-type(5)'));

    selectValueDropDown(siteToResetValues);

    cellsConform.getText().then(function(conforms) {

        // conforms is a string Array, each one is the text of one cell of 5th column
        conforms.forEach(function(conform, rowIndex) {

            if(conform === 'true') {
                var row = element.all(by.css('#datatableDir tr').get(rowIndex);

                row.element(by.css('button[id^="btnEdit-US"]')).click();

                row.element(by.css('input[type="checkbox"]')).click();

                row.element(by.css('button[id^="btnSubmit-US"]')).click();

                browser.sleep(3000)
            }
        });
    });

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM