0

I cannot get Selenium & Chrome work on a WS2016, with the following dependencies versions:

  • .NET Framework 4.5 installed
  • Latest Chrome 104.0.5112.81, entreprise version, installed in %programfiles(x86)%
  • Latest Selenium webdrive & support packages 4.0.3
  • Chromedriver v104.0.5112.79

Here is the PowerShell code i use to run Selenium...

# make sure chrome & chromedriver is not already running
taskkill /f /im chromedriv*

# set path as its a prerequisite, this path contains the selenium .dll's & chromedriver binary
$workingPath = "C:\users\(redacted)\documents\devs\script"
if (($env:Path -split ';') -notcontains $workingPath) {
    $env:Path += ";$workingPath"
}

# load the selenium classes
Add-Type -Path "$($workingPath)\WebDriver.dll"

$ChromeDrvOptions = [OpenQA.Selenium.Chrome.ChromeDriverService]::CreateDefaultService()

# tried to add some logging, it logs nothing more than the console output :(
$ChromeDrvOptions.LogPath = "$workingPath\logging\chromedriver.log"
$ChromeDrvOptions.EnableVerboseLogging = $true
$ChromeDrvOptions.EnableAppendLog = $true

# tried with & without increasing the launch timeout as i could read on other forums threads...
$ts = new-timespan -minutes 3
$ChromeDrvOptions.InitializationTimeout=$ts

# tried with & without specific port, made sure that its not used already
$ChromeDrvOptions.Port=5555 


$ChromeOptions = [OpenQA.Selenium.Chrome.ChromeOptions]::new()
$ChromeOptions.AddArguments("user-data-dir=$workingPath\chromeprofile")
$ChromeOptions.AddArguments('--profile-directory=Default')
$ChromeOptions.AddArguments('start-maximized')
$ChromeOptions.BinaryLocation = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"

#$ChromeDriver = New-Object OpenQA.Selenium.Chrome.ChromeDriver($ChromeOptions)
$ChromeDriver = New-Object OpenQA.Selenium.Chrome.ChromeDriver($ChromeDrvOptions,$ChromeOptions)

The result is...

Starting ChromeDriver 104.0.5112.79 (3cf3e8c8a07d104b9e1260c910efb8f383285dc5-refs/branch-heads/5112@{#1307}) on port 5555
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Impossible de se connecter au serveur distant
Impossible de se connecter au serveur distant
Impossible de se connecter au serveur distant
Impossible de se connecter au serveur distant
Impossible de se connecter au serveur distant
Impossible de se connecter au serveur distant
Impossible de se connecter au serveur distant
Impossible de se connecter au serveur distant
Impossible de se connecter au serveur distant
Impossible de se connecter au serveur distant
New-Object : Exception lors de l'appel de «.ctor» avec «2» argument(s): «Cannot start the driver service on
http://localhost:20066/»
Au caractère Ligne:32 : 18
+         return @(& $origNewObject @psBoundParameters)
+                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation : (:) [New-Object], MethodInvocationException
    + FullyQualifiedErrorId :ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

i'm running out of ideas... without more logging options i dont even have a clue of the potential problem source...

Thanks in advance,
Arnaud

Arnaud
  • 31
  • 4
  • Don't use parentheses when calling the `New-Object` _command_. In _argument parsing mode_ the `,` operator creates an array, so you are actually passing only one parameter that is an array. OTOH, when using the `new()` method (which is the recommended way), you have to use parentheses: `$ChromeDriver = [OpenQA.Selenium.Chrome.ChromeDriver]::new($ChromeDrvOptions, $ChromeOptions)` – zett42 Aug 05 '22 at 13:38
  • See also https://stackoverflow.com/a/48779223/7571258 – zett42 Aug 05 '22 at 13:41
  • Hello @zett42, thanks for the answer. I've tried with the constructor `$ChromeDriver = [OpenQA.Selenium.Chrome.ChromeDriver]::new($ChromeDrvOptions,$ChromeOptions)`, same behavior `ChromeDriver was started successfully. Impossible de se connecter au serveur distant [...] Exception lors de l'appel de « .ctor » avec « 2 » argument(s) : « Cannot start the driver service on http://127.0.0.1:40000/ »` – Arnaud Aug 08 '22 at 07:53
  • Are you running a local firewall software? You may have to allow connections to 127.0.0.1 (localhost) through port 40000. – zett42 Aug 08 '22 at 08:59
  • We got an antivirus which takes control on local firewall, i've checked that there is no blockage at this level. To be sure i've created in/out rules to allow port 40000, no more success :(. Edit : in addition, i've whitelisted the hashes of chromedriver binary & selenium DLL. Tried to run chromedriver as admin, same thing. – Arnaud Aug 08 '22 at 10:02
  • Have a look into Windows event logs if there are any errors at the time you run this script. – zett42 Aug 08 '22 at 10:48
  • @zett42 already done :(, there is absolutely nothing in the application & system logs related to the command. There is sysmon installed as well on the computer, i can only see that the powershell binary is running the command with args : `C:\temp\selenium\chromedriver.exe" --port=40000 --verbose --append-log --log-path="C:\temp\selenium\logging\chromedriver.log`. Nothing more... The chromedriver.log contains the same "so verbose" lines as in the console. – Arnaud Aug 08 '22 at 15:41
  • Sorry, out of ideas. :( – zett42 Aug 08 '22 at 20:22

1 Answers1

0

Remove log filename from LogPath

$ChromeDrvOptions.LogPath = "$workingPath\logging\chromedriver.log"

$ChromeDrvOptions.LogPath = "$workingPath\logging"
Xvadrom
  • 11
  • 1