Selenium Basic VBA でファイルダウンロード先が変更できない


fujifuji  2024-04-02 08:43:23  No: 151432  IP: 192.*.*.*

Selenium Basic VBAの初心者です。
chromeのプロファイルを指定したら
ファイルのダウンロード先が変更できないのですが
なにかいい方法はございますか?


Dim driver As New Selenium.WebDriver
Dim myBy As New By
Dim siteURL As String
Dim elm As Selenium.WebElement
Dim sKey As New Selenium.Keys


'プロファイルパスを指定
Dim str As String: str = "C:\Users\" & Environ("USERNAME") & "\AppData\Local\Google\Chrome\test"
driver.AddArgument ("--user-data-dir=" & str)
driver.AddArgument ("--profile-directory=Profile1")
driver.AddArgument "disable-gpu"
driver.AddArgument "start-maximized"

  Dim DL_Path As String: DL_Path = "C:********************************************"

  'ファイルのダウンロード先の変更
With driver
.SetPreference "download.default_directory", DL_Path 'ダウンロード先の指定
.SetPreference "download.directory_upgrade", True 'ダウロードフォルダアップデート
.SetPreference "download.prompt_for_download", False '自動ダウンロード
.SetPreference "plugins.always_open_pdf_externally", True
End With


'指定のURLに移動する
siteURL = "http://****************************"
Call driver.Start("chrome")
driver.Get siteURL

  
  'ファイルのダウンロード
Set elm = driver.FindElementByXPath("/html/body/table/*************************************")
Call elm.Click



driver.Close
Set driver = Nothing

編集 削除