Private Sub Use_DicAdd()
Dim Driver As New ChromeDriver
Driver.Get "https://the-internet.herokuapp.com/tables"
Dim eles(1) As WebElements
Set eles(0) = Driver.FindElementsByCss("#table1 tbody tr td:nth-child(1)")
Set eles(1) = Driver.FindElementsByCss("#table1 tbody tr td:nth-child(2)")
Dim Dic As New Dictionary 'Newが必須
Dim i As Integer
For i = 1 To eles(0).Count
Dic.Add eles(0).Item(i).Text, eles(1).Item(i).Text 'キーもアイテムもテキストを登録しているため、Driver配下の処理とはならない。
Next i
Debug.Print Dic.Count
Debug.Print Dic.Get("Smit", "Not Exist")
Dic.Set "hoge", "age"
Debug.Print Dic.Count
Debug.Print Dic.Get("hoge", "Not Exist")
Debug.Print Dic.Item("hoge")
Debug.Print Dic.ContainsKey("Smith")
Dim Key, Item
Key = Dic.Keys
Item = Dic.Values
For i = 0 To Dic.Count - 1
Debug.Print Key(i) & " : " & Item(i)
Next i
Dic.ToExcel
Dic.Clear
Dic.ToExcel
Driver.Quit
End Sub
Get_DicObject
Private Sub Get_DicObject()
Dim Driver As New ChromeDriver
Driver.Get "https://the-internet.herokuapp.com/tables"
Dim eles(1) As WebElements
Set eles(0) = Driver.FindElementsByCss("#table1 tbody tr td:nth-child(1)")
Set eles(1) = Driver.FindElementsByCss("#table1 tbody tr td:nth-child(2)")
Dim Dic As New Dictionary 'Newが必須
Dim i As Integer
For i = 1 To eles(0).Count
Dic.Add eles(0).Item(i).Text, eles(1).Item(i) 'アイテムはオブジェクト
Next i
Dim ele As WebElement
Set ele = Dic("Smith")
Debug.Print ele.Text
End Sub
Get_DriverInfo
Private Sub Get_DriverInfo()
Dim Driver As New ChromeDriver, ele As WebElement
Driver.Get "https://google.co.jp"
Dim info As Dictionary
Set info = Driver.ExecuteScript("return {" & _
"agent: navigator.userAgent," & _
"lang: navigator.userLanguage," & _
"Name: navigator.appCodeName," & _
"Activation: navigator.userActivation.hasBeenActive," & _
"driver: navigator.webdriver," & _
"cookie: document.cookie };")
Debug.Print info("Activation")
Debug.Print info("cookie")
Debug.Print info("driver")
Driver.Quit
End Sub
Get_EleInfo
Private Sub Get_EleInfo()
Dim Driver As New ChromeDriver, ele As WebElement
Driver.Get "https://www.pref.kyoto.jp/kenkoshishin/pdfdown.html"
Set ele = Driver.FindElementByPartialLinkText("飲酒")
Dim info As selenium.Dictionary
Set info = ele.ExecuteScript("return {" & _
"link: this.href," & _
"agent: navigator.userAgent," & _
"lang: navigator.userLanguage," & _
"cookie: document.cookie };")
Debug.Print info("link")
Debug.Print info("agent")
End Sub