2016-02-26 48 views
1

我在跟隨頁面對象模式的量角器。在下面的代碼我匹配的用戶名,然後點擊編輯按鈕StaleElementReferenceError:陳舊的元素引用:元素未附加到頁面文檔即將到來當我點擊按鈕

this.clickEditButton = function (userName) {   
    element.all(by.repeater('u in users')).each(function (elem) { 
     elem.element(by.css('td:nth-child(1)')).getText().then(function (value) {     
      if (value == userName) { 
       elem.element(by.css("a[href*='#/organisation/editUser/31']")).click(); 

      } 
     }); 
    });  
}; 

頁打開成功,但它拋出「StaleElementReferenceError:陳舊的元素參考:元素沒有被附加到頁面文件」

主要方法:

userDirectoryPage.clickEditButton('EditUser1');    
    userEditPage.addBasicDetails('', 'Timon', 'Thompson', '[email protected]', 'abc', 'abc', 'Testing'); 

有沒有人有一些建議如何解決這個問題?

回答

1

這裏的問題是,您正在使用each() - 單擊編輯按鈕時,DOM會更改,並且對下一個用戶元素的引用將變爲「過時」。

您需要使用filter()代替:

this.clickEditButton = function (userName) {   
    element.all(by.repeater('u in users')).filter(function (elem) { 
     elem.element(by.css('td:nth-child(1)')).getText().then(function (value) {     
      return value === userName; 
     }); 
    }).first().element(by.css("a[href*='#/organisation/editUser/31']")).click();  
}; 
+0

@ Alecxe-的解決方案,通過返回元素文本爲我工作。非常感謝。你太棒了。 –

相關問題