
VBAについて質問です。
以下のVBAを用いて、Googleマップで車の移動時間を約72万個ほど算出しようとしています。
100個ほど移動時間を算出したぐらいで、「実行時エラー7、No Such Element Error, Element not faund for Id = section-directions-trip-0」と表示され、以下のVBAの '移動手段"車"で検索のDo While dvr.FindElementById("section-directions-trip-0") Is Nothingが黄色くなります。
対処法をご教授くださいませんか。
以下VBA
Sub Test()
Call 車での所要時間(Worksheets("Sheet1").Range("A1:D722752"))
End Sub
Function 車での所要時間(r As Range) As String
Dim dvr As New Selenium.ChromeDriver '参照:Selenium Type Library
Dim Keys As New Selenium.Keys
dvr.Start "chrome"'GoogleMapを開きます
dvr.Get "https://www.google.com/maps/dir/"Do While dvr.FindElementByClass("tactile-searchbox-input") Is Nothing
Loop
Dim iRow As Long
For iRow = 1 To r.Rows.Count
'出発地目的地に緯度経度を設定
dvr.FindElementByXPath("//div[@id=""sb_ifc50""]/input").Clear
dvr.FindElementByXPath("//div[@id=""sb_ifc51""]/input").Clear
dvr.FindElementByXPath("//div[@id=""sb_ifc50""]/input").SendKeys r(iRow, 1) &","&r(iRow, 2)
dvr.FindElementByXPath("//div[@id=""sb_ifc51""]/input").SendKeys r(iRow, 3) &","&r(iRow, 4)
'移動手段"車"で検索
If iRow = 1 Then
dvr.FindElementByXPath("//img[@aria-label=""車""]").Click
Else
dvr.SendKeys Keys.Enter
End If
Do While dvr.FindElementById("section-directions-trip-0") Is Nothing
Loop
r(iRow, 5) = dvr.FindElementByClass("Fk3sm").Text
Next
End Function

0 コメント