2
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?

起動済みのEdgeに対して、VBAから操作する方法(Selenium Basic)

Last updated at Posted at 2024-08-12

前回投稿した記事では、新しくEdgeを立ちあげて操作する方法となり、
すでに表示しているブラウザに対しては操作が出来ません。

今回の記事では、Webサービスでログインするところまでは、手動で操作しその先を自動化したいときなどに利用できる方法になります。

デバッグ機能を提供するためのリモートデバッグポートを指定し、そこから接続する方法となります。

準備

前回の記事同様に

  1. Microsoft Edge WebDriver
  2. Selenium
  3. .NET Framework
    を用意します。

「remote debugging port」を指定してブラウザを立ちあげる

  1. Edgeのショートカットを作成
  2. プロパティを立ちあげる
  3. リンク先を以下のように設定
"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" -remote-debugging-port=9222

image.png

作成したショートカットからEdgeを立ちあげて、コマンドプロンプトでnetstatを叩いてport9222でリスニング状態であることを確認します。

>netstat -ano | findstr :9222
  TCP         127.0.0.1:9222         0.0.0.0:0              LISTENING       5944

もし、正しくポートが開いていない場合はEdgeの設定で以下2つをOFFにしてみましょう。

  • スタートアップブースト
  • Microsoft Edgeが終了しても...

image.png

動作確認

Sub BrowserTest()
  Dim driver As New Selenium.WebDriver
  ' リモートデバッグポートを指定
  driver.SetCapability "ms:edgeOptions", "{""debuggerAddress"":""127.0.0.1:9222""}"
  
  driver.Start "edge"
  driver.Get "https://google.com/"
  driver.Close
  Set driver = Nothing
End Sub

次回、TinySelenium(Seleniumとか.NET Frameworkなどのインストールが不要)を利用して、起動済みブラウザを操作する方法を(検証中なので実現できれば)書きます。

2
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
2
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?