跳至主要内容

isSelected

将返回 <option><input> 元素(类型为复选框或单选按钮)当前是否被选中的布尔值。

用法
$(selector).isSelected()
示例
index.html
<select name="selectbox" id="selectbox">
<option value="John Doe">John Doe</option>
<option value="Layla Terry" selected="selected">Layla Terry</option>
<option value="Bill Gilbert">Bill Gilbert"</option>
</select>

isSelected.js
it('should detect if an element is selected', async () => {
let element = await $('[value="Layla Terry"]');
console.log(await element.isSelected()); // outputs: true

element = await $('[value="Bill Gilbert"]')
console.log(await element.isSelected()); // outputs: false
});

欢迎!我如何帮助您?

WebdriverIO AI Copilot