我无法让Selenium & Chrome在WS2016上工作,其依赖版本如下:
installed
中
下面是用于运行Selenium的PowerShell代码..。
# 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)
结果是..。
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
我的想法不多了..。如果没有更多的日志记录选项,我甚至不知道潜在的问题来源.
提前谢谢你,
阿诺德
发布于 2022-09-29 21:26:38
从LogPath中删除日志文件名
$ChromeDrvOptions.LogPath = "$workingPath\logging\chromedriver.log"
$ChromeDrvOptions.LogPath = "$workingPath\logging"
https://stackoverflow.com/questions/73248065
复制相似问题