Vai al contenuto principale

isSelected

Restituirà true o false a seconda che un elemento <option> o <input> di tipo checkbox o radio sia attualmente selezionato o meno.

Utilizzo
$(selector).isSelected()
Esempi
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
});
Restituisce
  • <Boolean> return: true se l'elemento è selezionato

Welcome! How can I help?

WebdriverIO AI Copilot