我經常使用下面的輔助函數來等待一個元素的存在或顯示。也許給他們一個嘗試,量角器將阻止,直到這些返回true
。也許給他們一個去。
module.exports = {
/**
* Block until an element is displayed on the page.
*
* @param {object} elem
* The element to watch for.
*
* @param {number} [customTimeout=10000]
* How long to wait for `elem` to appear.
*/
waitForElementToBeDisplayed: function (elem, customTimeout) {
var timeout = customTimeout || 10000;
browser.wait(function() {
return elem.isDisplayed().then(
function (visible) {
return visible;
},
function() {
return false;
}
);
}, timeout, 'failed to find element ' + elem.locator());
},
/**
* Block until an element is present on the page.
*
* @param {Object} elem
* The element to watch for.
*
* @param {Number} [customTimeout=10000]
* How long to wait for 'elem' to appear.
*/
waitForElementToBePresent: function (elem, customTimeout) {
var timeout = customTimeout || 10000;
browser.wait(function() {
return elem.isPresent().then(
function (visible) {
return visible;
},
function() {
return false;
}
);
}, timeout, 'Element not present: ' + elem.locator());
}
}
你試圖點擊的元素,最有可能在一個框架內..你能證實嗎? – sircapsalot
另外,你能告訴我們,目標元素是否有'id =「male」',或者它是'name =「male」 – sircapsalot