I'm trying to open an instance of Google Chrome using ChromeWebDriver and MSXML2.ServerXMLHTTP
on VBA. The code works fine to open a new instance of the browser, but when I try to send to the WebDriver a custom user-data-dir (stored in D:\Profiles\tdmsoares\Desktop\tmpChromeUserData\User Data
it doesn't work:
Private Function SendRequest() As Dictionary
Dim client As Object
Set client = CreateObject("MSXML2.ServerXMLHTTP") 'ServerXMLHTTP
client.Open "POST", "http://localhost:9515/session"
client.setRequestHeader "Content-Type", "application/json"
Dim strJsonRequest As String
strJsonRequest = 'the comments bellow was made intentionally to show different ways I tried
'strJsonRequest = "{""capabilities"":{""alwaysMatch:""{""args"":""[--user-data-dir=D:/Profiles/tdmsoares/Desktop/tmpChromeUserData/User Data]""},}""sessionId"":""""}"
'strJsonRequest = "{""capabilities"":{""args"":""[--user-data-dir=D:\Profiles\tdmsoares\Desktop\tmpChromeUserData\User Data\]""},""sessionId"":""}"
'strJsonRequest = "{""capabilities"":{},{""desiredCapabilities"":{""args"":""[--user-data-dir=D:\Profiles\tdmsoares\Desktop\tmpChromeUserData\User Data]""},""sessionId"":""""}
'strJsonRequest = "{""capabilities"":{""userDataDir"":""D:\\Profiles\\tdmsoares\\Desktop\\tmpChromeUserData\\User Data\\]""},""sessionId"":""""}"
'strJsonRequest = "{""capabilities"":{""goog:chromeOptions:args"":""[--[user-data-dir=D:\\Profiles\\tdmsoares\\Desktop\\tmpChromeUserData\\User Data]""},""sessionId"":""""}
client.send strJsonRequest
Do While client.readyState < 4
DoEvents
Loop
Set SendRequest = JsonConverter.ParseJson(client.responseText)
End Function
Notes:
- When trying to see the result of object
client
fromMSXML2.ServerXMLHTTP
usingDebug.print client.responseText
I get:
{"value":{"capabilities":{"acceptInsecureCerts":false,"browserName":"chrome","browserVersion":"91.0.4472.124","chrome":{"chromedriverVersion":"91.0.4472.101 (af52a90bf87030dd1523486a1cd3ae25c5d76c9b-refs/branch-heads/4472@{#1462})","userDataDir":"D:\\Profiles\\tdmsoares\\AppData\\Local\\Temp\\scoped_dir7064_314199858"},"goog:chromeOptions":{"debuggerAddress":"localhost:52688"},"networkConnectionEnabled":false,"pageLoadStrategy":"normal","platformName":"windows","proxy":{},"setWindowRect":true,"strictFileInteractability":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"unhandledPromptBehavior":"dismiss and notify","webauthn:extension:largeBlob":true,"webauthn:virtualAuthenticators":true},"sessionId":"e29d73791d5eec0dfcf2f51426233979"}}
This means the user-data-dir is set to Temp although the atempts to change this
I look at documentation of WebDriver at W3.org and https://chromedriver.chromium.org/capabilities but still now I didn't find a solution for this
I'm not using Selenium (which have a lot of resources on internet)