Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛 Bug]: Dotnet Error in 4.11.0 when using ChromeDriverService.CreateDefaultService() #12564

Closed
ZianAtFirstWatch opened this issue Aug 16, 2023 · 46 comments

Comments

@ZianAtFirstWatch
Copy link

What happened?

When using ChromeDriverService.CreateDefaultService() to instantiate a ChromeDriver, the error "Unable to obtain chrome using Selenium Manager" occurs. This started happening in 4.11.0, but was fine in 4.10.0.

How can we reproduce the issue?

# This PowerShell code should be saved as a file with a ".ps1" extension. It uses the C# Nuget Packages' DLLs.
# They can be obtained by downloading the Nuget packages as ZIP files (https://www.nuget.org/packages/Selenium.Support/ and https://www.nuget.org/packages/Selenium.WebDriver) and copying the DLLs from the lib\net45 folder inside each ZIP file.

Function New-ChromeDriver {
    [CmdletBinding(
        SupportsShouldProcess,
        ConfirmImpact = 'Low'
    )]
    param(
        [Parameter(Mandatory)][string]$ScriptPath
    )
    $private:result = $null
    Initialize-Selenium -ScriptPath $ScriptPath
    $private:chromeDriverService = [OpenQA.Selenium.Chrome.ChromeDriverService]::CreateDefaultService()
    $private:chromeDriverService.DriverServicePath = $ScriptPath

    $private:chromeOptions = New-Object OpenQA.Selenium.Chrome.ChromeOptions
    $private:chromeOptions.AddExcludedArguments("excludeSwitches", "enable-logging");

    if ($PSCmdlet.ShouldProcess("Create a new instance of ChromeDriver.")) {
        $private:result = New-Object -TypeName OpenQA.Selenium.Chrome.ChromeDriver -ArgumentList @($private:chromeDriverService, $private:chromeOptions)
    }

    $private:result
}

Function Initialize-Selenium([string]$ScriptPath) {
    #Required for Chrome
    if (($env:Path -split ';') -notcontains $ScriptPath) {
        $env:Path += ";$ScriptPath"
    }

    Import-Module "$($ScriptPath)\WebDriver.dll"
    Import-Module "$($ScriptPath)\WebDriver.Support.dll"
}

$FolderWithDllsAndChromeDriverExecutable = Read-Host -Prompt "Which folder has the WebDriver DLLs and ChromeDriver executable file?"
New-ChromeDriver -ScriptPath $FolderWithDllsAndChromeDriverExecutable

Relevant log output

https://www.selenium.dev/documentation/webdriver/troubleshooting/logging/ says ".NET does not currently have a Logging implementation".

Operating System

Windows 10

Selenium version

4.11.0

What are the browser(s) and version(s) where you see this issue?

Version 116.0.5845.97 (Official Build) (64-bit)

What are the browser driver(s) and version(s) where you see this issue?

ChromeDriver 116.0.5845.96 (1a391816688002153ef791ffe60d9e899a71a037-refs/branch-heads/5845@{#1382})

Are you using Selenium Grid?

No

@github-actions
Copy link

@ZianAtFirstWatch, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@titusfortner
Copy link
Member

I suspect the value of $ScriptPath does not have a trailing slash to indicate that it is a directory and not a file.
That bug has been fixed for the next release.
Further, you shouldn't need to specify a service any longer, since selenium will manage the drivers for you.

@ZianAtFirstWatch
Copy link
Author

Thanks for the good news about the next release.

Is there a GitHub issue # or some other URL I can visit to see the change?

What about when a trailing slash is included?

PS C:\Users\zchoy\Downloads\test copy> .\test.ps1
Which folder has the WebDriver DLLs and ChromeDriver executable file?: C:\Users\zchoy\Downloads\test copy
MethodInvocationException: C:\Users\zchoy\Downloads\test copy\test.ps1:11
Line |
11 | $private:chromeDriverService = [OpenQA.Selenium.Chrome.ChromeDriv …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Exception calling "CreateDefaultService" with "0" argument(s): "Unable to obtain chrome using Selenium Manager;
| For documentation on this error, please visit:
| https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location"

InvalidOperation: C:\Users\zchoy\Downloads\test copy\test.ps1:12
Line |
12 | $private:chromeDriverService.DriverServicePath = $ScriptPath
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| The property 'DriverServicePath' cannot be found on this object. Verify that the property exists and can be set.

New-Object: C:\Users\zchoy\Downloads\test copy\test.ps1:18
Line |
18 | … te:result = New-Object -TypeName OpenQA.Selenium.Chrome.ChromeDriver …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Exception calling ".ctor" with "2" argument(s): "Object reference not set to an instance of an object."

@titusfortner
Copy link
Member

titusfortner commented Aug 17, 2023

.NET is frustrating because we don't have good logging for what is going on.
The Service class constructor takes a String argument representing the path of the directory that the driver is in.
In Selenium 4.10, if it didn't find the driver in that directory it would ignore the whole thing and look on PATH.

In 4.11, Selenium doesn't ignore it, and if the driver isn't there it fails. The problem is that people were putting the full path including the file name, which was failing. So I added code to split up directory and file name automatically if someone passed in a file and not a directory. Except, .NET assumes that if there is no trailing slash that it is a file and not a directory, which broke things.

So. 4.11 you don't need to specify anything; delete any drivers on the system and Selenium should download everything that needs to be downloaded based on the Options class values. If there is a problem and you need to specify the location, make sure you are passing in only the directory that the driver is located in and use a trailing slash.

In 4.12 the conditional will be improved so that it figures out if it is a file first rather than assuming the lack of a trailing slash makes it a file and not a directory.

@ChrisBloom-TH
Copy link

ChrisBloom-TH commented Aug 17, 2023

Seeing this same output error on my side intermittently with the following log after a simple startup. No chromedriver exists in the bin directory / on any system path, we're relying on Selenium Manager to download the driver at runtime. Hopefully this log is potentially a bit more helpful.

Sample code
ChromeOptions options = new ChromeOptions();

                options.AddArguments("-auth-server-whitelist=*.companyurl.com");
                options.AddArguments("-auth-negotiate-delegatewhitelist=*.companyurl.com");
                options.AddArguments("-auth-schemes=digest,ntlm,negotiate");

              options.AddUserProfilePreference("download.default_directory", @"C:\Automation\VSTS\Other\Downloads");

                newDriver = new ChromeDriver(ChromeDriverService.CreateDefaultService(), options, TimeSpan.FromSeconds(180));

DEBUG[13:22:12.252]: Exception Starting Chrome Driver OpenQA.Selenium.NoSuchDriverException: Unable to obtain chrome using Selenium Manager; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location ---> OpenQA.Selenium.WebDriverException: Error starting process: C:\Automation\VSTS\SeleniumDriver\bin\Release\selenium-manager/windows/selenium-manager.exe --browser "chrome" --output json ---> OpenQA.Selenium.WebDriverException: Selenium Manager process exited abnormally with 65 code: C:\Automation\VSTS\SeleniumDriver\bin\Release\selenium-manager/windows/selenium-manager.exe --browser "chrome" --output json
{
"logs": [
{
"level": "ERROR",
"timestamp": 1692292932,
"message": "error sending request for url (https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json): error trying to connect: An existing connection was forcibly closed by the remote host. (os error 10054)"
}
],
"result": {
"code": 65,
"message": "error sending request for url (https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json): error trying to connect: An existing connection was forcibly closed by the remote host. (os error 10054)",
"driver_path": "",
"browser_path": ""
}
}

at OpenQA.Selenium.SeleniumManager.RunCommand(String fileName, String arguments)
--- End of inner exception stack trace ---
at OpenQA.Selenium.SeleniumManager.RunCommand(String fileName, String arguments)
at OpenQA.Selenium.SeleniumManager.DriverPath(DriverOptions options)
at OpenQA.Selenium.DriverFinder.FullPath(DriverOptions options)
--- End of inner exception stack trace ---
at OpenQA.Selenium.DriverFinder.FullPath(DriverOptions options)
at OpenQA.Selenium.Chrome.ChromeDriverService.CreateDefaultService(ChromeOptions options)
at OpenQA.Selenium.Chrome.ChromeDriverService.CreateDefaultService()
at KeyWordDriver.Selenium.DriverHelper.CreateRemoteDriver(Boolean TempDriver, Boolean skipIfMobile) in C:\VSTS_work\7\s\SeleniumDriver\Selenium\DriverHelper.cs:line 1440

@ZianAtFirstWatch
Copy link
Author

.NET is frustrating because we don't have good logging for what is going on. The Service class constructor takes a String argument representing the path of the directory that the driver is in. In Selenium 4.10, if it didn't find the driver in that directory it would ignore the whole thing and look on PATH.

In 4.11, Selenium doesn't ignore it, and if the driver isn't there it fails. The problem is that people were putting the full path including the file name, which was failing. So I added code to split up directory and file name automatically if someone passed in a file and not a directory. Except, .NET assumes that if there is no trailing slash that it is a file and not a directory, which broke things.

So. 4.11 you don't need to specify anything; delete any drivers on the system and Selenium should download everything that needs to be downloaded based on the Options class values. If there is a problem and you need to specify the location, make sure you are passing in only the directory that the driver is located in and use a trailing slash.

In 4.12 the conditional will be improved so that it figures out if it is a file first rather than assuming the lack of a trailing slash makes it a file and not a directory.

Unfortunately, the error happens even when $env:path contains the path of the directory with a trailing slash and without the name of the file. The path is the last entry in the following text.

C:\Program Files\PowerShell\7;C:\Program Files\Eclipse Adoptium\jdk-11.0.18.10-hotspot\bin;C:\Program Files\Microsoft MPI\Bin\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\PROGRAMDATA\WEBEX\WEBEX\319\;C:\PROGRAMDATA\WEBEX\;C:\Program Files\SourceGear\Common\DiffMerge\;c:\Program Files (x86)\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\;C:\Program Files\Azure Data Studio\bin;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files\Liquid Technologies\Liquid Studio 2021\XmlDataBinder19\Redist19\cpp\win32\bin;C:\Program Files\Liquid Technologies\Liquid Studio 2021\XmlDataBinder19\Redist19\cpp\win64\bin;C:\Program Files\PuTTY\;C:\Program Files\Liquid Technologies\Liquid Studio\XmlDataBinder20\Redist20\cpp\win32\bin;C:\Program Files\Liquid Technologies\Liquid Studio\XmlDataBinder20\Redist20\cpp\win64\bin;C:\PROGRAM FILES (X86)\WEBEX\WEBEX\319\;C:\PROGRAM FILES (X86)\WEBEX\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\TortoiseHg\;C:\Program Files (x86)\Microsoft SQL Server\160\DTS\Binn\;C:\Program Files\PowerShell\7\;C:\Users\zchoy\AppData\Local\Microsoft\WindowsApps;C:\Users\zchoy\AppData\Local\Programs\Fiddler;C:\Users\zchoy\AppData\Local\GitHubDesktop\bin;C:\Users\zchoy\AppData\Local\Microsoft\WindowsApps;C:\Users\zchoy\.dotnet\tools;C:\Program Files\Azure Data Studio\bin;C:\Users\zchoy\documents\computer issues\sysinternals;;C:\Users\zchoy\Downloads\test copy\

@titusfortner
Copy link
Member

@ChrisBloom-TH that's a different error from this one. Selenium Manager should be catching issues with not connecting and using cache if found. @bonigarcia what causes the code 65 there? Anything SM can do to address it?

@ZianAtFirstWatch I'm not referring to $env:path, I'm referring to $ScriptPath.

@bonigarcia
Copy link
Member

Error code 65 is thrown by Selenium Manager when an exception is caught in the logic execution. It means "data error" and typically is caused by some inconsistent error in the user data. In this case, it seems to be a connectivity issue:

"error sending request for url (https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json): error trying to connect: An existing connection was forcibly closed by the remote host. (os error 10054)"

Maybe some proxy setup is required.

@titusfortner
Copy link
Member

@bonigarcia can we capture/ignore this error the same way we do if the system is offline?

@titusfortner
Copy link
Member

(if there is something already cached that works, we should be able to use that)

@bonigarcia
Copy link
Member

(if there is something already cached that works, we should be able to use that)

When the driver is already in the cache, it is used by Selenium Manager.

@bonigarcia can we capture/ignore this error the same way we do if the system is offline?

In this issue, it seems there is a connectivity problem: An existing connection was forcibly closed by the remote host. I believe it is a legitimate error, and we should not ignore it.

@titusfortner
Copy link
Member

Aren't we checking known-good-versions-with-downloads.json before we know if there's something in the cache?

@bonigarcia
Copy link
Member

Eventually, yes. That endpoint should be read to refresh the metadata (i.e., the resolved driver version), ensuring that what's in the cache is still valid. The point is what you said "if there is something already cached that works". We need to ask the endpoints again to ensure that the cache works.

A fallback mechanism is to use the latest driver in the cache when there is some problem (such as connectivity or any other exception). I implemented this fallback in WebDriverManager but not in Selenium Manager because, precisely, it is a fallback, i.e., it is not the optimal solution.

For instance, the optimal solution to this issue would be to detect what is causing the intermittent connectivity issues. My guess is that a problem which is related to the network (e.g., because of a proxy or firewall) on the user side.

Being said that. If we want, we can implement that fallback (i.e., get whatever the last driver is on the cache). It could be the default way of working for the offline mode. Also, in the online (i.e., default) mode, Selenium Manager can retry in offline mode if some error happens. It is a fallback, not the optimal solution, but maybe it works for a number of cases.

@titusfortner
Copy link
Member

A fallback mechanism is to use the latest driver in the cache when there is some problem (such as connectivity or any other exception)

I don't think this is even necessarily a fallback, though. I may want to run my tests against localhost without being online. I shouldn't need to be online if I have something valid cached.

I think we should throw a warning if there's a problem in our normal operations and still provide a valid driver whenever we can.

Maybe it is a real problem and they will have to figure it out when the browser version gets updated next, or maybe it is a weird intermittent issue that hopefully no one ever has to look at because we accommodate for it.

@StevenTN615
Copy link

StevenTN615 commented Aug 26, 2023

I'm not trying to hijack this thread, but this message is specifically for titusfortner. You said in this reply to the OP

Further, you shouldn't need to specify a service any longer, since selenium will manage the drivers for you.

I can get the OP's PowerShell code to work if I pass the full path (with the trailing slash) to the ChromeDriverService in it's constructor . However, if I comment out those lines for creating the ChromeDriverService, and only attempt to create the ChromeDriver passing in the ChromeOptions exclusively such as:

$private:result = New-Object -TypeName OpenQA.Selenium.Chrome.ChromeDriver -ArgumentList @($private:chromeOptions)

I end up getting the following exception:

New-Object : Exception calling ".ctor" with "1" argument(s): "Unable to obtain chrome using Selenium Manager

What am I missing if I don't need to specify the service any more? I would like to have Selenium keep my chromedriver.exe updated automatically, instead of having to use a separate script to do it.

I can manually execute the Selenium-Manager CLI to create the proper chromedriver.exe in the .cache folder, but the WebDriver.dll doesn't seem to do it for me automatically. I'm using the 4.11 WebDriver.dll for .Net 4.8.

Thanks.

@titusfortner
Copy link
Member

@diemol the primary issue with this is that the binary itself doesn't adjust to the fact that the user might be offline when trying to run the test with a valid driver already in the cache. I'm a little confused about how we are doing ttl vs checking the current driver version and browser version. If they match we don't need to call out again to update things.

@StevenTN615 I think this fixes your issue: #12534

@StevenTN615
Copy link

@titusfortner Thanks for getting back to me. I did look at that link you sent, but still am having issues. I tried loading up the DriverFinder, but I then get an exception:

Cannot find type [OpenQA.Selenium.Remote.Service.DriverFinder]: verify that the assembly containing this type is
loaded.

I'm not sure what assembly I need to load that contains the DriverFinder. I'm just trying to update some PowerShell code to use Selenium 4.11 and wanted the browser driver to automatically get found and loaded instead of manually doing it. So confused.

@titusfortner
Copy link
Member

@StevenTN615 sorry, I meant you need to wait for me to merge that PR and release Selenium 4.12. I'm planning to do that Monday if everything goes well.

@StevenTN615
Copy link

@titusfortner Thanks, I knew I was confused for a reason. Looking forward to trying Selenium 4.12.

@diemol diemol added this to the 4.12 milestone Aug 28, 2023
@nuthanbanad
Copy link

@titusfortner I am using the same Selenium version 4.11.0 and chrome browser version 116.0.5845.140 and getting same error message as below when running my C# selenium automation scripts intermittently.

"Unable to obtain chrome using Selenium Manager; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location "

I observed another behavior that this issue is also happening when the chrome browser is in updating state.. and works fine once browser update is finished.

Below is my code to instantiate chromedriver. Please let me know If I am doing anything wrong.
service = ChromeDriverService.CreateDefaultService();
service.HideCommandPromptWindow = true;
ChromeOptions options = new ChromeOptions();
options.AddArgument("no-sandbox");
options.AddArguments("--headless");
options.AddArgument("--window-size=1920,1080");
options.AddUserProfilePreference("disable-popup-blocking", "true");
chromeDriver = new ChromeDriver(service, options, TimeSpan.FromMinutes(3));

@titusfortner
Copy link
Member

Need to wait for 4.12 to make sure things are good.

@diemol diemol modified the milestones: 4.12, 4.13 Sep 4, 2023
@nvborisenko
Copy link
Member

@nuthanbanad please try the latest 4.12.4 and share full exception output if any. Thanks.

@StevenTN615
Copy link

I downloaded the C# package for 4.12.4 and extracted the webdriver.dll. When I run the OP's code for PowerShell and remove the instantiation of the ChromeDriverService and only try to create the ChromeDriver object passing in only the ChromeOptions, I still end up with the same error as with 4.11.

New-Object : Exception calling ".ctor" with "1" argument(s): "Unable to obtain chrome using Selenium
Manager; For documentation on this error, please visit:
https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location"
At C:\Users\Steve\Documents\Backup\Task Scheduler Tasks\ZZZSeleniumTest2.ps1:31 char:27

  • ... te:result = New-Object -TypeName OpenQA.Selenium.Chrome.ChromeDriver ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException
    • FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCom
      mand

I don't know what I'm missing here in order to have the Selenium manager find the correct version of ChromeDriver.exe that I require.

Everything works fine if I manually put the chromedriver.exe in my script path, and create the ChromeDriverService, but I thought the whole point on the newer Selenium is to not have to create the DriverService.

Function New-ChromeDriver {
    [CmdletBinding(
        SupportsShouldProcess,
        ConfirmImpact = 'Low'
    )]
    param(
        [Parameter(Mandatory)][string]$ScriptPath
    )
    $private:result = $null
    Initialize-Selenium -ScriptPath $ScriptPath
    #$private:chromeDriverService = [OpenQA.Selenium.Chrome.ChromeDriverService]::CreateDefaultService($ScriptPath)


    $private:chromeOptions = New-Object OpenQA.Selenium.Chrome.ChromeOptions
    $private:chromeOptions.AddExcludedArguments("excludeSwitches", "enable-logging");

    if ($PSCmdlet.ShouldProcess("Create a new instance of ChromeDriver.")) {
        #$private:result = New-Object -TypeName OpenQA.Selenium.Chrome.ChromeDriver -ArgumentList @($private:chromeDriverService, $private:chromeOptions)
        $private:result = New-Object -TypeName OpenQA.Selenium.Chrome.ChromeDriver -ArgumentList @($private:chromeOptions)
    }

    $private:result


}

Function Initialize-Selenium([string]$ScriptPath) {
    Import-Module "$($ScriptPath)WebDriver.dll"
}

$FolderWithDllsAndChromeDriverExecutable = "C:\Users\Steve\Documents\Backup\Task Scheduler Tasks\Library\SeleniumModule\"
New-ChromeDriver -ScriptPath $FolderWithDllsAndChromeDriverExecutable

@nvborisenko
Copy link
Member

Ok, you unpack the package yourself, without any package manager.

Then you should make sure the following folders structure:

Selenium.WebDriver.dll
selenium-manager/windows/selenium-manager.exe

So, you are missing selenium-manager.exe.

@StevenTN615
Copy link

Thanks for getting back to me, but my ignorance is still getting the best of me.

I have WebDriver.dll located in the following directory:
C:\Users\Steve\Documents\Backup\Task Scheduler Tasks\Library\SeleniumModule\

Should selenium-manager.exe be added in the following directory:
C:\Users\Steve\Documents\Backup\Task Scheduler Tasks\Library\SeleniumModule\selenium-manager\windows\

Or is the directory not relative to where WebDriver.dll is located?

I've tried it by putting selenium-manager.exe in
C:\Users\Steve\Documents\Backup\Task Scheduler Tasks\Library\SeleniumModule\selenium-manager\windows
but I still get the same exception as above.

@nvborisenko
Copy link
Member

nvborisenko commented Sep 8, 2023

It should be

C:\Users\Steve\Documents\Backup\Task Scheduler Tasks\Library\SeleniumModule\Selenium.WebDriver.dll
C:\Users\Steve\Documents\Backup\Task Scheduler Tasks\Library\SeleniumModule\selenium-manager\windows\selenium-manager.exe

Just to have clean discussion and understanding where we are, please share now your code you use, and exception you get.

@StevenTN615
Copy link

I'm basically using the same code as the OP, but I hard coded the path to WebDriver.dll and I removed the instantiation of the Chrome Driver Service since I keep getting told it is no longer required. I also renamed WebDriver.dll to Selenium.WebDriver.dll since that is what you showed in your example (although I don't think that should matter.

I also put selenium-manager.exe in the folder structure that you specified.

Thanks for your patience.

Still get the same exception:

New-Object : Exception calling ".ctor" with "1" argument(s): "Unable to obtain chrome using Selenium 
Manager; For documentation on this error, please visit: 
https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location"
At C:\Users\Steve\Documents\Backup\Task Scheduler Tasks\ZZZSeleniumTest3.ps1:16 char:27
+ ... te:result = New-Object -TypeName OpenQA.Selenium.Chrome.ChromeDriver  ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCom 
   mand
Function New-ChromeDriver {
    [CmdletBinding(
        SupportsShouldProcess,
        ConfirmImpact = 'Low'
    )]
    param(
        [Parameter(Mandatory)][string]$ScriptPath
    )

    $private:result = $null
    Initialize-Selenium -ScriptPath $ScriptPath
    $private:chromeOptions = New-Object OpenQA.Selenium.Chrome.ChromeOptions
    $private:chromeOptions.AddExcludedArguments("excludeSwitches", "enable-logging");

    if ($PSCmdlet.ShouldProcess("Create a new instance of ChromeDriver.")) {
        $private:result = New-Object -TypeName OpenQA.Selenium.Chrome.ChromeDriver -ArgumentList @($private:chromeOptions)
    }

    $private:result
}

Function Initialize-Selenium([string]$ScriptPath) {
    Import-Module "$($ScriptPath)Selenium.WebDriver.dll"
}

$FolderWithDllsAndChromeDriverExecutable = "C:\Users\Steve\Documents\Backup\Task Scheduler Tasks\Library\SeleniumModule\"
#$FolderWithDllsAndChromeDriverExecutable = Read-Host -Prompt "Which folder has the WebDriver DLLs and ChromeDriver executable file?"
New-ChromeDriver -ScriptPath $FolderWithDllsAndChromeDriverExecutable

@nvborisenko
Copy link
Member

Weird thing here we don't see full exception stack trace including inner exceptions. Do you know how to poll it out in powershell?

@StevenTN615
Copy link

Not particularly, but I added the following try/catch block around when I create the ChromeDriver object.

        try {
            $private:result = New-Object -TypeName OpenQA.Selenium.Chrome.ChromeDriver -ArgumentList @($private:chromeOptions)
        } catch {
            $Error[0].Exception.StackTrace
            Write-Host " "
            $Error[0].Exception.InnerException.StackTrace
            Write-Host " "
            $Error[0].StackTrace
        }

This is the output, if that helps.

   at System.Management.Automation.DotNetAdapter.AuxiliaryConstructorInvoke(MethodInformation methodInforma
tion, Object[] arguments, Object[] originalArguments)
   at System.Management.Automation.DotNetAdapter.ConstructorInvokeDotNet(Type type, ConstructorInfo[] const
ructors, Object[] arguments)
   at Microsoft.PowerShell.Commands.NewObjectCommand.CallConstructor(Type type, ConstructorInfo[] construct
ors, Object[] args)
 
   at OpenQA.Selenium.DriverFinder.FullPath(DriverOptions options)
   at OpenQA.Selenium.Chromium.ChromiumDriver.GenerateDriverServiceCommandExecutor(DriverService service, D
riverOptions options, TimeSpan commandTimeout)
   at OpenQA.Selenium.Chromium.ChromiumDriver..ctor(ChromiumDriverService service, ChromiumOptions options,
 TimeSpan commandTimeout)
   at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeDriverService service, ChromeOptions options, TimeSpa
n commandTimeout)
   at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeOptions options)

@nvborisenko
Copy link
Member

Much better, let's improve to see inner exceptions:

$Error[0].Exception.ToString()

I mean execute .ToString() method which will show us what we want.

@StevenTN615
Copy link

Okay. Output here:

System.Management.Automation.MethodInvocationException: Exception calling ".ctor" with "1" argument(s): "Unable to obtain chrome using Selenium Manager; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location" ---> OpenQA.Selenium.NoSuchDriverException: Unable to obtain chrome using Selenium Manager; For documentation on this error, please visit: 
https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location ---> System.TypeInitializationException: The type initializer for 'OpenQA.Selenium.SeleniumManager' threw an exception. ---> OpenQA.Selenium.WebDriverException: Unable to locate or obtain Selenium Manager binary at C:\WINDOWS\system32\WindowsPowerShell\v1.0\selenium-manager/windows/selenium-manager.exe
   at OpenQA.Selenium.SeleniumManager..cctor()
   --- End of inner exception stack trace ---
   at OpenQA.Selenium.SeleniumManager.DriverPath(DriverOptions options)
   at OpenQA.Selenium.DriverFinder.FullPath(DriverOptions options)
   --- End of inner exception stack trace ---
   at OpenQA.Selenium.DriverFinder.FullPath(DriverOptions options)
   at OpenQA.Selenium.Chromium.ChromiumDriver.GenerateDriverServiceCommandExecutor(DriverService service, DriverOptions options, TimeSpan commandTimeout)
   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 OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeOptions options)
   --- End of inner exception stack trace ---
   at System.Management.Automation.DotNetAdapter.AuxiliaryConstructorInvoke(MethodInformation methodInformation, Object[] arguments, Object[] originalArguments)
   at System.Management.Automation.DotNetAdapter.ConstructorInvokeDotNet(Type type, ConstructorInfo[] constructors, Object[] arguments)
   at Microsoft.PowerShell.Commands.NewObjectCommand.CallConstructor(Type type, ConstructorInfo[] constructors, Object[] args)
 

I see that it says it can't find selenium-manager.exe @ C:\WINDOWS\system32\WindowsPowerShell\v1.0\selenium-manager/windows/selenium-manager.exe, so I added it exactly as the path states into the system32 sub directory. Still gives the same exception. Could it be that the path after selenium-manager all the \ become /?

@StevenTN615
Copy link

StevenTN615 commented Sep 9, 2023

@nvborisenko I think I was mixing the 4.11 WebDriver.dll with the 4.12 selenium-manager.exe, so I deleted everything, re-pulled the 4.12.4 C# package, unpacked the package, and moved the WebDriver.dll to my test directory ("C:\Users\Steve\Documents\Backup\Task Scheduler Tasks\Library\SeleniumModule"), and the selenium-manager.exe to "C:\WINDOWS\system32\WindowsPowerShell\v1.0\selenium-manager/windows/" and re-ran my test script. Now I get a different exception, so that's a step in the right direction.

System.Management.Automation.MethodInvocationException: Exception calling ".ctor" with "1" argument(s): "Unable to obtain chrome using Selenium Manager; For documentation on this error, please visit: 
https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location" 
---> OpenQA.Selenium.NoSuchDriverException: Unable to obtain chrome using Selenium Manager; For documentation on this error, please visit: 
https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location 
---> System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.
   at OpenQA.Selenium.SeleniumManager.RunCommand(String fileName, String arguments)
   at OpenQA.Selenium.SeleniumManager.DriverPath(DriverOptions options)
   at OpenQA.Selenium.DriverFinder.FullPath(DriverOptions options)
   --- End of inner exception stack trace ---
   at OpenQA.Selenium.DriverFinder.FullPath(DriverOptions options)
   at OpenQA.Selenium.Chromium.ChromiumDriver.GenerateDriverServiceCommandExecutor(DriverService service, DriverOptions options, TimeSpan commandTimeout)
   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 OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeOptions options)
   --- End of inner exception stack trace ---
   at System.Management.Automation.DotNetAdapter.AuxiliaryConstructorInvoke(MethodInformation methodInformation, Object[] arguments, Object[] originalArguments)
   at System.Management.Automation.DotNetAdapter.ConstructorInvokeDotNet(Type type, ConstructorInfo[] constructors, Object[] arguments)
   at Microsoft.PowerShell.Commands.NewObjectCommand.CallConstructor(Type type, ConstructorInfo[] constructors, Object[] args)


I even installed the newtonsoft.json module into PowerShell, and imported it into my script, but still get the same exception. 🤷‍♂️

@nvborisenko
Copy link
Member

You need place Newtonsoft.Json dll beside Selenium.WebDriver.dll. And all other dlls as dependencies of Selenium.

You can explorer dependencies here: https://www.nuget.org/packages/Selenium.WebDriver#dependencies-body-tab

@StevenTN615
Copy link

Thank you, thank you, thank you. This now works as it should.

The only difference from what you told me was selenium-manager.exe had to be put in the following Windows folder:

"C:\Windows\System32\WindowsPowerShell\v1.0\selenium-manager\windows\selenium-manager.exe"

It didn't work if selenium-manager.exe was placed relative to webdriver.dll:

C:\Users\Steve\Documents\Backup\Task Scheduler Tasks\Library\SeleniumModule\selenium-manager\windows\selenium-manager.exe

I can see that it now downloads and accesses chromedriver.exe in my user .cache directory.

Thanks again.

@nvborisenko
Copy link
Member

And this is strange, the location of selenium-manager.exe is predictable: https://github.com/SeleniumHQ/selenium/blob/5f3f7d096a75700e055effbe13cbc22117014e2c/dotnet/src/webdriver/SeleniumManager.cs#L46C16-L46C16

In any case it works for you, even if I have no explanation why :)

@titusfortner
Copy link
Member

To be clear, Selenium Manager needs to work without having to load custom dll's. It should "just work." If it does not just work with the latest version of Selenium, please let us know.

@StevenTN615
Copy link

@titusfortner Not sure what you meant by "Selenium Manager needs to work without having to load custom dll's." Does that mean it should work without me having to put Newtonsoft.Json.dll in the same folder as Webdriver.dll? When I didn't have Newtonsoft.Json.dll I got the exception as above.

@titusfortner
Copy link
Member

Selenium comes with all the dlls, you don't need to download or install anything else.

When you use Selenium 4.12.4 in your Selenium test, are you still getting an exception?

@StevenTN615
Copy link

Yes, I get the exception as above.

Like I told @nvborisenko, I manually downloaded the 4.12.4 nupkg, extracted webdriver.dll to my working directory, and extracted selenium-manager.exe to "C:\Windows\System32\WindowsPowerShell\v1.0\selenium-manager\windows\selenium-manager.exe". When I run my PowerShell test script I get the "Could not load file or assembly 'Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.", exception. It only worked after I put Newtonsoft.Json.dll in the same directory as my Webdriver.dll.

@titusfortner
Copy link
Member

Ah, I misunderstood, you are just debugging the problem locally. So for some reason Selenium is complaining about Newtonsoft.Json

@titusfortner titusfortner reopened this Sep 11, 2023
@nuthanbanad
Copy link

nvborisenko

I used latest version 4.12.4 and still got same exception. This is just a scheduled task on remote PC to run my app.exe which uses Selenium.

Below is the exception:

Unable to obtain chrome using Selenium Manager; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location
at OpenQA.Selenium.DriverFinder.FullPath(DriverOptions options)
at OpenQA.Selenium.Chromium.ChromiumDriver.GenerateDriverServiceCommandExecutor(DriverService service, DriverOptions options, TimeSpan commandTimeout)
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 OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeOptions options)
at DonwloadGroupDeviceListData.Form1.createSeleniumChromeBrowser()
at DonwloadGroupDeviceListData.Form1.<Form1_Shown>d__25.MoveNext()

@StevenTN615
Copy link

@nuthanbanad What helped me was when I dumped the toString() method on my exception per @nvborisenko suggestion. From that I was able to see 2 errors, selenium-manager.exe was in the wrong spot on my PC, and I needed Newtonsoft.Json.dll. Although @titusfortner says you shouldn't have to download any dependent dlls.

@nuthanbanad
Copy link

@StevenTN615 @nvborisenko

Okay I have updated my code to show ex.toString(). I'll provide the exception details again if it occurs anytime soon as this issue is random for me.

All my .dlls are in same folder. Please see attached screenshot.
Files

@titusfortner
Copy link
Member

@nvborisenko what is it that we need to do here?

@nvborisenko
Copy link
Member

nvborisenko commented Sep 11, 2023

I think we can close it because of initially it was about 4.11. Many things have been improved, let's force people to post new issue instead of adding new comments here.

Copy link

github-actions bot commented Dec 6, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants