SeleniumBasic CapabilitiesClass ブラウザ設定情報の取得

リファレンス

概要

ブラウザ情報の取得、ハンドル用のクラスを解説します。

オブジェクト設定

・変数宣言

Dim Cap As Dictionary

・親クラス:Manage

文法

Set Cap = driver.Manage.Capabilities
Cap.[メソッド]

メソッド・プロパティ

メソッド

スクロールできます
Name解説ShortExample
Add辞書に新たな値を追加Cap.Add "hoge", "age"
Clear辞書のクリアCap.Clear
ContainsKeyキーが存在すればTrue,無ければFalseを返す(完全一致検索)Debug.Print Cap.ContainsKey("version")
Get指定キーで登録された値を返す。キーが存在しない場合は第二引数を返す。Debug.Print Cap.Get("versio", "Not Exsist")
Set指定されたキーの値を設定。キーが無ければキーを新たに作成。Cap.Set "hoge", "sage"
ToExcelExcelへ出力

※Short Exampleは、動作確認ができたコードを記載しています。

プロパティ

スクロールできます
Name解説ShortExample
Countアイテム数を返すDebug.Print Cap.Count
Itemキーに対する値を返すDebug.Print Cap.Item("hoge")
Keysキーを配列で返すKey = Cap.Keys
Valuesアイテムを配列で返すItem = Cap.Values

※Short Exampleは、動作確認ができたコードを記載しています。

CapabilityName

Cap.Item(<検索値>)の検索値部分で指定できるCapabilityNameの一覧を作成しました。
"chrome", "goog:chromeOptions", "proxy", "timeouts"は、型式がDictionary型ですので、String型やBoolean型と同じ様に出力はできません。一度、オブジェクトに代入するか、子クラスのキー指定をする等の方法が必要になります。出力方法は、Exampleを参照ください。

スクロールできます
CapabilityName解説型式
acceptInsecureCertsセッションがデフォルトで全SSL 証明書を受け入れるかBoolean
acceptSslCertsSSL証明書を許可すべきかどうかBoolean
browserConnectionEnabledセッションがブラウザー接続を問い合わできるかBoolean
browserNameブラウザ名String
chromeChromeのバージョン、userDataDirの場所を返すDictionary
cssSelectorsEnabled要素検索のcssSelector利用可否Boolean
databaseEnabledデータベースの利用可否Boolean
goog:chromeOptionsChromeのオプション設定を返すDictionary
handlesAlertsセッションがポップアップと対話可否Boolean
hasTouchScreenタッチスクリーンの利用可否Boolean
javascriptEnabledjavascriptの利用可否Boolean
locationContextEnabledブラウザ位置環境の参照可否Boolean
mobileEmulationEnabledデスクトップ版Chromeからモバイル機器Chromeの利用可否Boolean
nativeEventsブラウザのマウスとキーボード入力シミュレートの利用可否Boolean
networkConnectionEnabledリモートエンドの接続可否Boolean
pageLoadStrategyページ読込み方法の取得(normal, eager, none)String
platformブラウザを操作するプラットフォーム名String
proxyプロキシサーバ情報Dictionary
rotatable回転可能可否Boolean
setWindowRectウィンドウの縦横サイズ設定可否Boolean
strictFileInteractability厳密な相互作用チェックのinput type = file 要素への適用可否Boolean
takesHeapSnapshotメモリーリークを見つける為のヒープのスナップショット取得機能利用可否Boolean
takesScreenshotブラウザ内でのスクリーンショット利用可否Boolean
timeouts各種タイムアウト情報を返すDictionary
unexpectedAlertBehaviour予期せぬアラートを無視するかどうかString
versionブラウザのバージョンString
webStorageEnabledウェブストレージの利用可否Boolean
webauthn:extension:credBlobセキュリティキー(credBlob)拡張機能利用可否Boolean
webauthn:extension:largeBlob資格情報に関連付けられた不透明なデータの保存可否Boolean
webauthn:virtualAuthenticatorsエンドポイントノードが全ての仮想認証コマンドをサポートするかどうかBoolean

※Short Exampleは、動作確認ができたコードを記載しています。

Example

Use_Capabilities

Private Sub Use_Capabilities()
    Dim driver As New ChromeDriver
    Dim Mng As Manage
    Dim Cap As Dictionary
    driver.Get "https://ja.wikipedia.org/wiki/"
    Set Cap = driver.Manage.Capabilities
    Cap.Add "hoge", "age"
    Debug.Print Cap.ContainsKey("version")
    Debug.Print Cap.Get("versio", "Not Exsist")
    Cap.Set "hoge", "sage"
    Debug.Print Cap.Item("hoge")
    Debug.Print Cap.Item("chrome")("chromedriverVersion")
    Debug.Print Cap.Count
    'Cap.ToExcel

    Dim Key, Item, i As Integer
    Key = Cap.Keys
    Item = Cap.Values
    For i = 0 To Cap.Count - 1
        Select Case Key(i)
        Case "chrome"
            Dim chrmDic As Dictionary
            Set chrmDic = Item(i)
            Debug.Print "chromedriverVersion: " & chrmDic.Item("chromedriverVersion")
            Debug.Print "userDataDir: " & chrmDic.Item("userDataDir")
        Case "goog:chromeOptions"
            Dim optDic As Dictionary
            Set optDic = Item(i)
            Debug.Print "debuggerAddress: " & optDic.Item("debuggerAddress")
        Case "proxy"
            Dim prxDic As Dictionary
            Set prxDic = Item(i)
            Debug.Print "proxy count: " & prxDic.Count
        Case "timeouts"
            Dim timeoutDic As Dictionary
            Set timeoutDic = Item(i)
            Debug.Print "implicit: " & timeoutDic.Item("implicit")
            Debug.Print "pageLoad: " & timeoutDic.Item("pageLoad")
            Debug.Print "script: " & timeoutDic.Item("script")
        Case Else
            Debug.Print Key(i) & " : " & Item(i)
        End Select
    Next i
    
    Cap.Clear
    driver.Quit
End Sub
よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!

この記事を書いた人

VBAを中心とした自動化、効率化の手法を紹介しています。現在は、SeleniumBasicのexamplesを紹介しています。その内、SeleniumBasic以外の手法も掲載したいと思っております。