2017-06-21 28 views
0

我試圖根據頁面中元素的可用性來獲取布爾值。當出現在頁面中的元素,我可以能夠得到,但如果該元素不存在,提示以下錯誤信息:無法使用cucumberjs驗證頁面中的元素可用性

browser.findElement(by.className('Welcome')).isDisplayed() 
browser.findElement(by.className('Welcome')).isPresent() 
element(by.className('Welcome')).isDisplayed() 
element(by.className('Welcome')).isPresent() 
+0

請張貼有關HTML – Gunderson

+0

顯示爲<按鈕類=「歡迎」的元件細節>。 – KAK

回答

0

「:

No element found using locator: By(css selector, .Welcome) 
NoSuchElementError: No element found using locator: By(css selector, .Welcome) 

我曾與下面的組合嘗試當頁面中的元素能夠變爲True時,但是如果元素不存在,則會收到以下錯誤消息「

該錯誤是因爲您正在調用isDisplayed()。你可以檢查一個元素是否存在,它將返回true/false並且沒有錯誤。但是,如果您對當前不存在的元素調用isDisplayed(),則會得到NoSuchElementError。這僅僅意味着元素還不存在。如果您需要等待它出現並且可見,那麼請使用Expected Conditions

0

如果元素不總是出現在DOM上,但只有在某些條件下才可以始終通過首先獲取所有數組通過該特定的CSS選擇的元素,然後確保長度> 0(意味着至少一個元素被發現):

element.all(by.className('Welcome')).count() 
    .then(function(elementsFound){ 
     expect(elementsFound>0,'element not found').to.equal(true); 
    }) 
相關問題