我還在學習量角器,所以我不確定這是一個簡單的答案,我沒有得到,但我只是想讓瀏覽器等待直到我檢索的屬性爲真。Browser.wait()直到.getAttribute()返回true
我正在測試this site的披薩選項。
完整代碼:
browser.get('https://material.angularjs.org/latest/#/demo/material.components.select');
var topping = element(by.model('topping'));
topping.click();
browser.wait(function() {
return topping.getAttribute('aria-expanded').then(function(value) {
return value == 'true';
});
}, 5000);
var toppingOptions = element.all(by.css('[role="option"]'));
toppingOptions.get(5).click();
expect(topping.getText()).toBe('Onion');
這給我的錯誤:
Element is not clickable at point (436, 693). Other element would receive the click:
<md-backdrop class="md-select-backdrop md-click-catcher md-default-theme"></md-backdrop>
還要說明一點,如果我topping.click()
後browser.wait()
,則測試通過之前把browser.sleep(1000);
。所以我知道剩下的測試不是失敗的。出於某種原因,等待呼叫不起作用。
我在想這可能與我試圖點擊的選項在點擊topping
時在技術上看不到這一事實有關,因爲它位於帶有滾動元素的組合框中。如果有人知道模擬滾動到「洋蔥」元素的好方法,那麼也會非常感激。
這似乎並沒有解決它。我仍然得到元素在點(x,y)錯誤處不可點擊。我可以看到被點擊的按鈕,然後一個選擇窗口開始彈出,但它似乎在該窗口完全加載之前嘗試點擊。我正在測試[本頁]的比薩餅部分(https://material.angularjs.org/latest/#/demo/material.components.select)以供參考。 –
@WesThompson明白了。你能分享到目前爲止你所擁有的完整代碼以及你得到的錯誤的堆棧跟蹤嗎?謝謝。 – alecxe
更新,感謝您願意幫助。 –