●seleniumBasicをインストールする。
https://florentbr.github.io/SeleniumBasic/
●NET Framework 3.5のランタイム
https://www.microsoft.com/ja-jp/download/details.aspx?id=21
●WebDriver(Edge)
該当バージョンをダウンロードし、解凍したexeをSeleniumBasicと同じフォルダにコピーする。
開発タブを挿入し、参照設定でSelenimuを設定する。
★Edge操作の参考
Sub Sophosログイン()
Dim driver As New SeleniumVBA.WebDriver
Dim element As WebElement
Set driver = SeleniumVBA.New_WebDriver
'新規でブラウザ(Edge)起動 プロファイルが別物で開く
driver.StartEdge ThisWorkbook.Path & "\msedgedriver.exe"
driver.OpenBrowser
'Sophoslogin画面表示
driver.NavigateTo "https://172.16.0.1:4444"
'■最大サイズに変更
driver.ActiveWindow.Maximize
'■Chromeで起動
'driver.StartEdge 'Edgeの場合は driver.Start "edge"
'driver.Get "https://172.16.0.1:4444/"
'Sophoslogin画面表示
'driver.NavigateTo "https://172.16.0.1:4444"
'■新しいタブを開く
'driver.ExecuteScript ("window.open('https://172.16.0.1:4444')") '対象のURLを開く
'■対象とするタブを一つ右にずらす(新規タブをフォーカスし、対象とする)
'driver.SwitchToNextWindow
'表示待ち(適宜調整)
driver.Wait 2000
'詳細を表示しないのボタンを押す
Set element = driver.FindElementByID("details-button")
element.Click
'詳細を表示しないのボタンを押す
Set element = driver.FindElementByID("proceed-link")
element.Click
'表示待ち(適宜調整)
driver.Wait 2000
'ユーザー名入力
Set element = driver.FindElementByName("username")
element.SendKeys "admin"
'パスワード入力
Set element = driver.FindElementByName("password")
element.SendKeys "Zaq12wsxcd?"
'ログインボタンを押す
Set element = driver.FindElementByName("loginbutton")
element.Click
'表示待ち(適宜調整)
driver.Wait 10000
'ネットワークを選択する
Set element = driver.FindElementByID("nav-network")
element.Click
'表示順序:料金が安い順
'Set element = driver.FindElementByID("s")
'element.SelectByVisibleText "料金が安い順"
'検索ボタンクリック
'Set element = driver.FindElementByID("searchModuleSubmit")
'element.Click
'表示待ち、兼、一時停止(適宜調整)
'driver.Wait 5000
'結果保存
'driver.SaveScreenshot ThisWorkbook.Path & "\ルート、運賃検索結果.png"
'driver.SaveHTMLToFile driver.GetPageSource, ThisWorkbook.Path & "\ルート、運賃検索結果.html"
End
End Sub