Private Sub Handle_Dropdown_List()
Dim Assert As New Selenium.Assert
Dim driver As New ChromeDriver
driver.Get "https://the-internet.herokuapp.com/dropdown"
driver.Wait 2000
Dim ele As SelectElement
Set ele = driver.FindElementById("dropdown").AsSelect
ele.SelectByText "Option 2"
driver.Wait 1500
ele.SelectByIndex 1
driver.Wait 1500
ele.SelectByValue "2"
Debug.Print ele.IsMultiple
Debug.Print "Selected: " & ele.SelectedOption.Text
Dim elms As WebElements, elm As WebElement
Set elms = ele.Options
For Each elm In elms
Debug.Print elm.Text
Next elm
driver.Wait 1500
' Stop
driver.Quit
End Sub
Multi_SelectElement
Private Sub Multi_SelectElement()
Dim Keys As New Selenium.Keys
Dim driver As New ChromeDriver
driver.Get "https://bayashita.com/p/entry/show/24"
Dim select_ele As SelectElement
Set select_ele = driver.FindElementByXPath("//*[contains(@id,'list1')]").AsSelect
Debug.Print "MultSelect: " & select_ele.IsMultiple
Dim i As Integer
For i = 0 To 4
select_ele.SelectByIndex i
Next i
select_ele.DeselectByIndex 0
select_ele.DeselectByText "複数選択可能なセレクトボックス・表示する値3"
select_ele.DeselectByValue "2"
select_ele.DeselectAll
For i = 0 To 4
select_ele.SelectByIndex i
Next i
Stop
Dim ele As WebElement, eles As WebElements
Set eles = select_ele.AllSelectedOptions
For Each ele In eles
Debug.Print ele.Text
Next ele
Stop
driver.Quit
End Sub