isExisting
如果元素存在于 DOM 中,则返回 true。
信息
与其他元素命令相反,WebdriverIO 不会等待元素存在来执行此命令。
用法
$(selector).isExisting()
示例
index.html
<div id="notDisplayed" style="display: none"></div>
<div id="notVisible" style="visibility: hidden"></div>
<div id="notInViewport" style="position:absolute; left: 9999999"></div>
<div id="zeroOpacity" style="opacity: 0"></div>
isExisting.js
it('should detect if elements are existing', async () => {
let elem = await $('#someRandomNonExistingElement')
let isExisting = await elem.isExisting()
console.log(isExisting); // outputs: false
elem = await $('#notDisplayed')
isExisting = await elem.isExisting()
console.log(isExisting); // outputs: true
elem = await $('#notVisible')
isExisting = await elem.isExisting()
console.log(isExisting); // outputs: true
elem = await $('#notInViewport')
isExisting = await elem.isExisting()
console.log(isExisting); // outputs: true
elem = await $('#zeroOpacity')
isExisting = await elem.isExisting()
console.log(isExisting); // outputs: true
});