-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Comments
@ZianAtFirstWatch, thank you for creating this issue. We will troubleshoot it as soon as we can. Info for maintainersTriage this issue by using labels.
If information is missing, add a helpful comment and then
If the issue is a question, add the
If the issue is valid but there is no time to troubleshoot it, consider adding the
If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C),
add the applicable
After troubleshooting the issue, please add the Thank you! |
I suspect the value of $ScriptPath does not have a trailing slash to indicate that it is a directory and not a file. |
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?
PS C:\Users\zchoy\Downloads\test copy> .\test.ps1 InvalidOperation: C:\Users\zchoy\Downloads\test copy\test.ps1:12 New-Object: C:\Users\zchoy\Downloads\test copy\test.ps1:18 |
.NET is frustrating because we don't have good logging for what is going on. 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. |
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
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 at OpenQA.Selenium.SeleniumManager.RunCommand(String fileName, String arguments) |
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.
|
@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 |
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:
Maybe some proxy setup is required. |
@bonigarcia can we capture/ignore this error the same way we do if the system is offline? |
(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.
In this issue, it seems there is a connectivity problem: |
Aren't we checking |
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. |
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. |
I'm not trying to hijack this thread, but this message is specifically for titusfortner. You said in this reply to the OP
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. |
@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 |
@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 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. |
@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. |
@titusfortner Thanks, I knew I was confused for a reason. Looking forward to trying Selenium 4.12. |
@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 "
Below is my code to instantiate chromedriver. Please let me know If I am doing anything wrong. |
Need to wait for 4.12 to make sure things are good. |
@nuthanbanad please try the latest 4.12.4 and share full exception output if any. Thanks. |
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
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 |
Ok, you unpack the package yourself, without any package manager. Then you should make sure the following folders structure:
So, you are missing |
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: Should selenium-manager.exe be added in the following directory: Or is the directory not relative to where WebDriver.dll is located? I've tried it by putting selenium-manager.exe in |
It should be
Just to have clean discussion and understanding where we are, please share now your code you use, and exception you get. |
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 |
Weird thing here we don't see full exception stack trace including inner exceptions. Do you know how to poll it out in powershell? |
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.
|
Much better, let's improve to see inner exceptions:
I mean execute |
Okay. Output here:
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 /? |
@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.
I even installed the newtonsoft.json module into PowerShell, and imported it into my script, but still get the same exception. 🤷♂️ |
You need place You can explorer dependencies here: https://www.nuget.org/packages/Selenium.WebDriver#dependencies-body-tab |
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:
It didn't work if selenium-manager.exe was placed relative to webdriver.dll:
I can see that it now downloads and accesses chromedriver.exe in my user .cache directory. Thanks again. |
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 :) |
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. |
@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. |
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? |
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. |
Ah, I misunderstood, you are just debugging the problem locally. So for some reason Selenium is complaining about Newtonsoft.Json |
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 |
@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. |
@nvborisenko what is it that we need to do here? |
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. |
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. |
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?
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
The text was updated successfully, but these errors were encountered: