0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【VBA】Edge操作の基本

Last updated at Posted at 2024-07-01

●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

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?