{"id":16122346,"url":"https://github.com/uezo/tinyseleniumvba","last_synced_at":"2025-03-16T08:32:51.206Z","repository":{"id":44931677,"uuid":"336267879","full_name":"uezo/TinySeleniumVBA","owner":"uezo","description":"A tiny Selenium wrapper written in pure VBA","archived":false,"fork":false,"pushed_at":"2022-01-17T23:13:43.000Z","size":85,"stargazers_count":61,"open_issues_count":37,"forks_count":17,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-03-14T17:08:06.156Z","etag":null,"topics":["selenium","vba","vba-excel"],"latest_commit_sha":null,"homepage":"","language":"VBA","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uezo.png","metadata":{"files":{"readme":"README.ja.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-05T12:39:31.000Z","updated_at":"2025-02-27T01:08:02.000Z","dependencies_parsed_at":"2022-09-20T07:53:10.578Z","dependency_job_id":null,"html_url":"https://github.com/uezo/TinySeleniumVBA","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uezo%2FTinySeleniumVBA","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uezo%2FTinySeleniumVBA/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uezo%2FTinySeleniumVBA/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uezo%2FTinySeleniumVBA/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uezo","download_url":"https://codeload.github.com/uezo/TinySeleniumVBA/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243809865,"owners_count":20351403,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["selenium","vba","vba-excel"],"created_at":"2024-10-09T21:10:42.969Z","updated_at":"2025-03-16T08:32:50.584Z","avatar_url":"https://github.com/uezo.png","language":"VBA","readme":"# TinySeleniumVBA\n\nA tiny Selenium wrapper written in pure VBA.\n\n[🇬🇧English version is here](https://github.com/uezo/TinySeleniumVBA/blob/main/README.md) : \n\n[🇧🇷Versão em Português](https://github.com/tdmsoares/TinySeleniumVBA/blob/ReadmeInPortuguese/README.pt.md)\n\n\n# ✨ 特長\n\n- インストール不要: VBAのみで書かれているので、インストール権限のない人でもすぐにブラウザ自動操作に取り掛かることができます\n- 便利なヘルパー機能: FindElement(s)By*、フォームへの値の入出力、クリックやその他便利な機能を提供しています\n- オープンな仕様: 基本的にこのラッパーはWebDriverのHTTPクライアントですので、ラッパーの使い方を学ぶことはWebDriverの仕様を知ることと同義です。無駄になるものはありません\nhttps://www.w3.org/TR/webdriver/\n\n\n# 📦 セットアップ\n\n1. ツール＞参照設定から `Microsoft Scripting Runtime` に参照を通してください\n\n1. `WebDriver.cls`、`WebElement.cls`、`Capabilities.cls`、`JsonConverter.bas`をプロジェクトに追加してください\n    - 最新版 (v0.1.3): https://github.com/uezo/TinySeleniumVBA/releases/tag/v0.1.3\n\n1. WebDriverをダウンロードしてください（ブラウザのメジャーバージョンと同じもの）\n    - Edge: https://developer.microsoft.com/ja-jp/microsoft-edge/tools/webdriver/\n    - Chrome: https://chromedriver.chromium.org/downloads\n\n# 🪄 使い方\n\n```vb\nPublic Sub main()\n    ' WebDriverの開始 (Edge)\n    Dim Driver As New WebDriver\n    Driver.Edge \"path\\to\\msedgedriver.exe\"\n    \n    ' ブラウザを開く\n    Driver.OpenBrowser\n    \n    ' Googleへ移動\n    Driver.Navigate \"https://www.google.co.jp/?q=selenium\"\n\n    ' 検索テキストボックスを取得\n    Dim searchInput\n    Set searchInput = Driver.FindElement(By.Name, \"q\")\n    \n    ' テキストボックスの値を取得\n    Debug.Print searchInput.GetValue\n    \n    ' テキストボックスに値を入力\n    searchInput.SetValue \"yomoda soba\"\n    \n    ' 検索ボタンのクリック\n    Driver.FindElement(By.Name, \"btnK\").Click\n    \n    ' 再読み込み - ヘルパーメソッドを提供していない場合でも、ドライバーコマンドを直接実行することができます\n    Driver.Execute Driver.CMD_REFRESH\nEnd Sub\n```\n\n# 🐙 ブラウザーオプション\n\nブラウザーオプションを指定するには `Capabilities` を使うと便利です。以下はヘッドレスモード（非表示モード）でブラウザを起動する例です。\n\n```vb\n' Start web driver\nDim Driver As New WebDriver\nDriver.Chrome \"C:\\path\\to\\chromedriver.exe\"\n\n' Configure Capabilities\nDim cap As Capabilities\nSet cap = Driver.CreateCapabilities()\ncap.AddArgument \"--headless\"\n' Use SetArguments if you want to add multiple arguments\n' cap.SetArguments \"--headless --xxx -xxx\"\n\n' Show Capabilities as JSON for debugging\nDebug.Print cap.ToJson()\n\n' Open browser\nDriver.OpenBrowser cap\n```\n\n`Capabilities`の仕様はブラウザ毎に異なりますので、以下のWebサイト等にてご確認ください。\n- Chrome: https://chromedriver.chromium.org/capabilities\n- Edge: https://docs.microsoft.com/en-us/microsoft-edge/webdriver-chromium/capabilities-edge-options\n\n\n# ⚡️ JavaScriptの実行\n\n`ExecuteScript()`を利用することで、ブラウザ上で任意のJavaScriptコードを実行することができます。\n\n```vb\n' Start web driver\nDim Driver As New WebDriver\nDriver.Chrome \"C:\\path\\to\\chromedriver.exe\"\n\n' Open browser\nDriver.OpenBrowser\n\n' Navigate to Google\nDriver.Navigate \"https://www.google.co.jp/?q=liella\"\n\n' Show alert\nDriver.ExecuteScript \"alert('Hello TinySeleniumVBA')\"\n\n' === Use breakpoint to CLOSE ALERT before continue ===\n\n' Pass argument\nDriver.ExecuteScript \"alert('Hello ' + arguments[0] + ' as argument')\", Array(\"TinySeleniumVBA\")\n\n' === Use breakpoint to CLOSE ALERT before continue ===\n\n' Pass element as argument\nDim searchInput\nSet searchInput = Driver.FindElement(By.Name, \"q\")\nDriver.ExecuteScript \"alert('Hello ' + arguments[0].value + ' ' + arguments[1])\", Array(searchInput, \"TinySeleniumVBA\")\n\n' === CLOSE ALERT and continue ===\n\n' Get return value from script\nDim retStr As String\nretStr = Driver.ExecuteScript(\"return 'Value from script'\")\nDebug.Print retStr\n\n' Get WebElement as return value from script\nDim firstDiv As WebElement\nSet firstDiv = Driver.ExecuteScript(\"return document.getElementsByTagName('div')[0]\")\nDebug.Print firstDiv.GetText()\n\n' Get complex structure as return value from script\nDim retArray\nretArray = Driver.ExecuteScript(\"return [['a', '1'], {'key1': 'val1', 'key2': document.getElementsByTagName('div'), 'key3': 'val3'}]\")\n\nDebug.Print retArray(0)(0)  ' a\nDebug.Print retArray(0)(1)  ' 1\n\nDebug.Print retArray(1)(\"key1\") ' val1\nDebug.Print retArray(1)(\"key2\")(0).GetText()    ' Inner Text\nDebug.Print retArray(1)(\"key2\")(1).GetText()    ' Inner Text\nDebug.Print retArray(1)(\"key3\") ' val3\n```\n\n# ❤️ 謝辞\n\n[VBA-JSON](https://github.com/VBA-tools/VBA-JSON) という Tim Hall さんが開発したVBA用JSONコンバーターはHTTPクライアントを作る上でとても役に立ちました。このすばらしいライブラリは当該ライブラリのライセンスのもとでリリースに含まれています。ありがとうございます！\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuezo%2Ftinyseleniumvba","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuezo%2Ftinyseleniumvba","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuezo%2Ftinyseleniumvba/lists"}