Selecting an item from the list
WebdriverIO provides three ways to select an item from an element:
selectByVisibleText
: Matches the option based on its visible textselectByIndex
: Matches the option based on its index location (0-based)selectByAttribute
: Matches the option based on a specific attribute and its value
For example, if we wanted to select the third month from a list of months, each of these approaches could work:
await lstMonth.selectByVisibleText ("March"); await lstMonth.selectByAttribute ("value", "March"); await lstMonth.selectByIndex(2); // 0 based index
Often, the WebdriverIO selectByVisibleText
method works fine as the default method in a wrapper, but there are times when a list element needs to interact with open of the alternative ways.
In each case, we should validate that the correct value has been selected:
await lstElement.selectByVisibleText (item); let itemValue = await listElement.getText...