fysh711426 / UndetectedChromeDriver

GNU General Public License v3.0
166 stars 60 forks source link

Error: 'invalid argument: entry 0 of 'firstMatch' #54

Open yeucodonvn opened 1 year ago

yeucodonvn commented 1 year ago

please help me. i write a function but not running windows 10 and selenium 4.10

string chromeDriverPath = Path.Combine(pathdir, "chromedriver_109.0.5414.exe"); ;
string profilepath = "";
string browserExecutablePath = Path.Combine(pathdir, "Chrome-bin", "chrome.exe");
profilepath = Path.Combine(pathdir, "profile", i.ToString());
if (File.Exists(profilepath))
{
    Directory.CreateDirectory(profilepath);
}
var chromeOptions= new ChromeOptions();
chromeOptions.AddArgument("--disable-blink-features=AutomationControlled");
chromeOptions.AddAdditionalOption("useAutomationExtension", false);
chromeOptions.AddExcludedArgument("--enable-blink-features");
chromeOptions.AddExcludedArgument("--enable-logging");
chromeOptions.AddExcludedArgument("enable-automation");
chromeOptions.AddExcludedArgument("--no-service-autorun");
chromeOptions.AddExcludedArgument("--test-type");
driver = UndetectedChromeDriver.Create(
    options: chromeOptions,
    driverExecutablePath: chromeDriverPath,
    hideCommandPromptWindow: true,
    //userDataDir: profilepath,
    browserExecutablePath: browserExecutablePath
    );

this is error on AddExcludedArgument. i cannot fix. please help me

OpenQA.Selenium.WebDriverArgumentException
  HResult=0x80131500
  Message=invalid argument: entry 0 of 'firstMatch' is invalid
from invalid argument: cannot parse capability: goog:chromeOptions
from invalid argument: unrecognized chrome option: excludeSwitches
  Source=WebDriver
  StackTrace:
   at OpenQA.Selenium.WebDriver.UnpackAndThrowOnError(Response errorResponse)
   at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.WebDriver.StartSession(ICapabilities desiredCapabilities)
   at OpenQA.Selenium.WebDriver..ctor(ICommandExecutor executor, ICapabilities capabilities)
   at OpenQA.Selenium.Chromium.ChromiumDriver..ctor(ChromiumDriverService service, ChromiumOptions options, TimeSpan commandTimeout)
   at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeDriverService service, ChromeOptions options, TimeSpan commandTimeout)
   at SeleniumUndetectedChromeDriver.UndetectedChromeDriver..ctor(ChromeDriverService service, ChromeOptions options, TimeSpan commandTimeout)
   at SeleniumUndetectedChromeDriver.UndetectedChromeDriver.Create(ChromeOptions options, String userDataDir, String driverExecutablePath, String browserExecutablePath, Int32 port, Int32 logLevel, Boolean headless, Boolean noSandbox, Boolean suppressWelcome, Boolean hideCommandPromptWindow, Nullable`1 commandTimeout, Dictionary`2 prefs, Action`1 configureService)
   at firefox.firefox.Build() in F:\C#\firefox\firefox.cs:line 148

  This exception was originally thrown at this call stack:
    [External Code]
    firefox.firefox.Build() in firefox.cs
graysuit commented 3 months ago

Solved by removing following line: chromeOptions.AddExcludedArgument("enable-automation");

If you want to hide "Chrome is being controlled by ..." Use this line:

Options.AddArgument($"--app={Url}");

Instead of:

Driver.Navigate().GoToUrl(Url);