個人的にめちゃくちゃハマってしまったので、だれかの役に立つかもしれないメモ
SeleniumVBAがすごそうでソースを眺めたり遊んでいたら、 設定ファイル(iniファイル)が出力できることに気が付いた。
WebDriverクラスのCreateSettingsFileをたたくと、実行したExcelファイルと同じ階層に、SeleniumVBA.iniが作成される。
1.SeleniumVBA.ini 出力コード
1 2 3 4 5 6 7 |
Sub CreateIniFileSample() Dim driver As WebDriver Set driver = New_WebDriver driver.CreateSettingsFile End Sub |
GitHub - GCuser99/SeleniumVBA: A comprehensive Selenium wrapper for browser automation developed for MS Office VBA
A comprehensive Selenium wrapper for browser automation developed for MS Office VBA - GitHub - GCuser99/SeleniumVBA: A c...
SeleniumVBA.ini 生ファイル
VBAでここまで作りこんでいる。本当にすごい
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# This settings file is completely optional. For it to have effect, # it must be located in the same folder as the SeleniumVBA code # library, and be named "SeleniumVBA.ini". # If a value for an entry is not specified, then the system # default value will be used. # Note that all path-type entry values recognize the %[Environ]% syntax. # A few useful Environ values for reference: # %USERPROFILE%=C:\Users\[user name] # %APPDATA%=C:\Users\[user name]\AppData\Roaming # %LOCALAPPDATA%=C:\Users\[user name]\AppData\Local # %TEMP%=C:\Users\[user name]\AppData\Local\Temp [GENERAL] # The driver_location_folder system defaults to Downloads folder. # The default_io_folder system defaults to the active vba project's # document location - leave this blank to use default. # Valid values for command_window_style are vbHide (default), # vbNormalFocus, vbMinimizedFocus, vbMaximizedFocus, vbNormalNoFocus, # and vbMinimizedNoFocus. # The system default values for implicit_wait, page_load_timeout, and # script_timeout are 0, 300000, and 30000 ms respectively. driver_location_folder=%USERPROFILE%\Downloads default_io_folder= command_window_style=vbHide implicit_wait=0 page_load_timeout=300000 script_timeout=30000 [AUTO-DRIVER-UPDATE] # If auto_detect_and_update=True (system default) then everytime # the WebDriver's Start* method is called, the Selenium driver's # version is checked against the corresponding browser version. # If the driver is not compatible with browser, it will be updated. # min_compatibility_level determines trigger for updating an # an out-of-date driver. System default is svbaBuildMajor. # Use svbaMinor for less frequent updating, and svbaExactMatch # for more frequent updating. auto_detect_and_update=True min_compatibility_level=svbaBuildMajor # Below are browser-specific initializations. # To automatically initialize a set of capabilities each time the # OpenBrowser method of WebDriver class is invoked, set the # preload_capabilities_file_path entry to the path of a valid json # capabilities file. Note that if preload_capabilities_file_path is # set to a blank value, or the entry is missing or commented out, # then this option is ignored. Use the SaveToFile method of the # WebCapabilities class to save a default set of capabilities # for pre-loading. # The system defaults for local_host_port: # Chrome - 9515, Edge - 9516, Firefox - 4444, IE - 5555 [CHROME] preload_capabilities_file_path= local_host_port=9515 [EDGE] preload_capabilities_file_path= local_host_port=9516 [FIREFOX] preload_capabilities_file_path= local_host_port=4444 [INTERNET EXPLORER] preload_capabilities_file_path= local_host_port=5555 [PDF_DEFAULT_PRINT_SETTINGS] # Valid units values are svbaInches (default) or svbaCentimeters. # Valid orientation values are svbaPortrait (default) or svbaLandscape. units=svbaInches page_height=11 page_width=8.5 margin_bottom=.393701 margin_top=.393701 margin_right=.393701 margin_left=.393701 background=False orientation=svbaPortrait print_scale=1 shrink_to_fit=True |
SeleniumVBA.iniで、msedgedriver.exeの格納先ファイルパスを指定
ソースを見ていたら、driver_location_folderがmsedgedriver.exe等、webdriverの格納先ファイルパスを探すようだ。
1 |
driver_location_folder=%USERPROFILE%\Downloads |
%USERPROFILE%\Downloads に例えば”C:\Users\papanda925\Documents\VBA_Local”等の直接パスを指定し、各ブラウザのwebdriverをダウンロード格納しておけば、SeleniumVBAが自動的にドライバを取得する処理をスキップできる。実務でインターネットに接続することもできない立場の方には、この設定は必要そう。
1 |
driver_location_folder="C:\Users\papanda925\Documents\VBA_Local" |
他、そもそもwebdriverクラスのStartxx(例:StartEdge)を実行する際に第1引数でも絶対パス指定ができるが、外部ファイルで制御したい場合はこちらもおすすめ
その他、SeleniumVBA.iniでおすすめそうな設定
デバッグ時だけかも
1 |
command_window_style=vbHide |
を
1 |
command_window_style=vbMinimizedNoFocus |
等の表示モードにすると、デバッグ時にwebdriverのプロンプトが表示されて便利(とくにプロセスをタスクマネージャーから落とすようなことを事態になるデバッグ発生時)
コメント