Set preference method giving compile error as "Argument not optional" in SeleniumVBA Set preference method giving compile error as "Argument not optional" in SeleniumVBA selenium selenium

Set preference method giving compile error as "Argument not optional" in SeleniumVBA


You have a couple of other issues with your code. First, you need to set the profile of the user directory prior to starting Chrome. So, this would need to be set before using the .Get() method.

Also, if you are using Dim .. As New in your declaration, you do not need to Set .. = New later on.

Finally, instead of using .SetPreference() to grab your user profile, just use .SetProfile() with persistent:=True.

And I should also mention that you do not need to include \Default to the profile, this is included automatically; and a personal preference would be for me to use %USERPROFILE% instead of hard coding the username in the filepath.

Dim driver As New ChromeDriverdriver.SetProfile "%USERPROFILE%\AppData\Local\Google\Chrome\User Data", Truedriver.AddArgument "--no-sandbox"driver.Get "https://www.gmail.com/"

For your specific issue, that error code implies that you are missing a required argument. .SetPreference requires two arguments:

  1. Key
  2. Value

But you only provided one.


Try remove the parentheses

driver.AddArgument "--no-sandbox"

if still not solved try with

driver.Get "https:www.gmail.com/"driver.AddArgument "--no-sandbox"driver.SetPreference "user-data-dir", "C:/Users/sagar/AppData/Local/Google/Chrome/User Data/Default"