Jump to content

ChromeDriver v136 Error: -user-data-dir


Go to solution Solved by SOLVE-SMART,

Recommended Posts

Posted (edited)
$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["--user-data-dir=C:\\Users\\' & @UserName & '\\AppData\\Local\\Google\\Chrome\\User Data\\", "--profile-directory=Default"]}}}}'


Getting this error from the chromedriver: DevTools remote debugging requires a non-default data directory. Specify this using --user-data-dir.

However, I have set the --user-data in the $sDesiredCapabilites. Can someone help and tell me what I am doing wrong?ย 

#include "wd_core.au3"
#include "wd_helper.au3"

_WD_Option('Driver', 'chromedriver.exe')
Local $iPort = _WD_GetFreePort(5555, 5600)
_WD_Option('Port', $iPort)
_WD_Option('DriverParams', '--port=' & $iPort & ' --verbose --log-path="' & @ScriptDir & '\chrome.log"')

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["--user-data-dir=C:\\Users\\' & @UserName & '\\AppData\\Local\\Google\\Chrome\\User Data\\", "--profile-directory=Default"]}}}}'

_WD_Startup()
Local $sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_LoadWait($sSession)

_WD_Navigate($sSession, "google.com")
_WD_LoadWait($sSession)

ย 

Edited by SkysLastChance

You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott

  • Solution
Posted (edited)

Hi @SkysLastChanceย ๐Ÿ‘‹ ,

unfortunately Google did some important changes by v136. I guess this should be helpful for you:
https://developer.chrome.com/blog/remote-debugging-port

The following code is untested, but should ๐Ÿคž work:

Local $sProfilePath = @UserProfileDir & '\AppData\Local\Google\Chrome\AutomationProfile'
      $sProfilePath = StringReplace($sProfilePath, '\', '\\')

Local Const $sDesiredCapabilities = StringFormat( _
    '{' & _
    '    "capabilities": {' & _
    '        "firstMatch": [' & _
    '            {}' & _
    '        ],' & _
    '        "alwaysMatch": {' & _
    '            "browserName": "chrome",' & _
    '            "goog:chromeOptions": {' & _
    '                "args": [' & _
    '                    "--remote-debugging-port=9222",' & _
    '                    "--user-data-dir=%s",' & _
    '                    "--profile-directory=Default"' & _
    '                ]' & _
    '            }' & _
    '        }' & _
    '    }' & _
    '}', $sProfilePath)

I added --remote-debugging-port and changed the profile path ($sProfilePath). Let me/us know if this helps ๐Ÿค .

Best regards
Sven

Edited by SOLVE-SMART

==> AutoIt related: ๐Ÿ”— GitHub, ๐Ÿ”— Discord Server, ๐Ÿ”— Cheat Sheet

Spoiler

๐ŸŒย Au3Forums

๐ŸŽฒ AutoIt (en) Cheat Sheet

๐Ÿ“Š AutoIt limits/defaults

๐Ÿ’Ž Code Katas: [...] (comming soon)

๐ŸŽญ Collection of GitHub users with AutoIt projects

๐Ÿžย False-Positives

๐Ÿ”ฎย Me on GitHub

๐Ÿ’ฌย Opinion about new forum sub category

๐Ÿ“‘ย UDF wiki list

โœ‚ย VSCode-AutoItSnippets

๐Ÿ“‘ย WebDriver FAQs

๐Ÿ‘จโ€๐Ÿซย WebDriver Tutorial (coming soon)

Posted
#include "wd_core.au3"
#include "wd_helper.au3"


; Create profile directory if it doesn't exist
Local $sUserDataDir = "C:\Script Prerequisites\ChromeDriverProfile"
If Not FileExists($sUserDataDir) Then
    DirCreate($sUserDataDir)
EndIf

_WD_Option('Driver', 'chromedriver.exe')
Local $iPort = _WD_GetFreePort(5555, 5600)
_WD_Option('Port', $iPort)
_WD_Option('DriverParams', '--port=' & $iPort & ' --verbose --log-path="' & @ScriptDir & '\chrome.log"')

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["user-data-dir=C:\\Script Prerequisites\\ChromeDriverProfile", "--profile-directory=Default", "--disable-extensions"], "excludeSwitches": [ "enable-automation"], "useAutomationExtension": false }}}}'

_WD_Startup()
Local $sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_LoadWait($sSession)

_WD_Navigate($sSession, "google.com")
_WD_LoadWait($sSession)

I did this but your solution was better. @SOLVE-SMART Thank you!

You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott

Posted (edited)
7 minutes ago, SkysLastChance said:

I did this but your solution was better. @SOLVE-SMART Thank you!

I'm glad it works. You're welcome.

๐Ÿ’ก Btw:
In case you want to avoid the json creation (capability string) on your own, you can use _WD_CapabilitiesAdd to create the string.
So no struggle with characters like { " : [ etc.

Best regards
Sven

Edited by SOLVE-SMART

==> AutoIt related: ๐Ÿ”— GitHub, ๐Ÿ”— Discord Server, ๐Ÿ”— Cheat Sheet

Spoiler

๐ŸŒย Au3Forums

๐ŸŽฒ AutoIt (en) Cheat Sheet

๐Ÿ“Š AutoIt limits/defaults

๐Ÿ’Ž Code Katas: [...] (comming soon)

๐ŸŽญ Collection of GitHub users with AutoIt projects

๐Ÿžย False-Positives

๐Ÿ”ฎย Me on GitHub

๐Ÿ’ฌย Opinion about new forum sub category

๐Ÿ“‘ย UDF wiki list

โœ‚ย VSCode-AutoItSnippets

๐Ÿ“‘ย WebDriver FAQs

๐Ÿ‘จโ€๐Ÿซย WebDriver Tutorial (coming soon)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...