跳至主要內容

selectByIndex

選擇具有特定索引的選項。

用法
$(selector).selectByIndex(index)
參數
名稱類型詳細資訊
index數字選項索引
範例
example.html
<select id="selectbox">
<option value="someValue0">uno</option>
<option value="someValue1">dos</option>
<option value="someValue2">tres</option>
<option value="someValue3">cuatro</option>
<option value="someValue4">cinco</option>
<option value="someValue5">seis</option>
</select>
selectByIndex.js
it('Should demonstrate the selectByIndex command', async () => {
const selectBox = await $('#selectbox');
console.log(await selectBox.getValue()); // returns "someValue0"
await selectBox.selectByIndex(4);
console.log(await selectBox.getValue()); // returns "someValue4"
});

歡迎!我能如何協助您?

WebdriverIO AI Copilot