Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 有人能帮我修复Powershell语言的代码吗?_C#_.net_Powershell_Selenium - Fatal编程技术网

C# 有人能帮我修复Powershell语言的代码吗?

C# 有人能帮我修复Powershell语言的代码吗?,c#,.net,powershell,selenium,C#,.net,Powershell,Selenium,我想将C#代码重写为PowerShell语言,但我不知道如何编写斜体代码。错误是:使用“2”参数调用“.ctor”时发生异常:“未创建会话:未找到匹配功能(SessionNotCreated)” C# 动力壳 Add-Type -Path 'F:\BaiduNetdiskDownload\selenium.webdriver.4.0.0-alpha04\lib\netstandard2.0\WebDriver.dll' Add-Type -Path 'F:\BaiduNetdiskDownloa

我想将C#代码重写为PowerShell语言,但我不知道如何编写斜体代码。错误是:使用“2”参数调用“.ctor”时发生异常:“未创建会话:未找到匹配功能(SessionNotCreated)”

C#

动力壳

Add-Type -Path 'F:\BaiduNetdiskDownload\selenium.webdriver.4.0.0-alpha04\lib\netstandard2.0\WebDriver.dll'
Add-Type -Path 'F:\BaiduNetdiskDownload\newtonsoft.json.12.0.3\lib\netstandard2.0\Newtonsoft.Json.dll'

$edgeOptions =New-Object OpenQA.Selenium.Edge.EdgeOptions([bool]$false)
$edgeOptions.BinaryLocation = 'C:\Program Files (x86)\Microsoft\Edge Dev\Application\msedge.exe'

$msedgedriverDir = "D:\Drivers"
$msedgedriverExe = "msedgedriver.exe"

$service =[OpenQA.Selenium.Edge.EdgeDriverService]::CreateDefaultService($msedgedriverDir,$msedgedriverExe, $false)
$driver =  New-Object OpenQA.Selenium.Edge.EdgeDriver($service, $edgeOptions)
错误

Exception calling ".ctor" with "2" argument(s): "session not created: No matching capabilities found (SessionNotCreated)"

对不起,但是没有。我认为powershell代码不起作用的原因可能是EdgeDriverService.CreateDefaultService是一个静态方法,它使var服务成为一个类,但在powershell中,$service是一个静态方法。然而,我不知道如何编写代码只是一个粗略的猜测,但是
$driver=[OpenQA.Selenium.Edge.EdgeDriver]::new($service,$edgeOptions)
那么可以工作了吗?顺便说一句:导致错误的那一行是
var driver=new EdgeDriver(service,edgeOptions)
,不是你突出显示的那一行。非常感谢你,西奥。代码起作用了。你能告诉我它为什么起作用吗?为什么我不能使用New Object来新建一个类实例?谢谢提醒,mklement0。我强调代码只是因为我认为代码可能是这个问题的关键。
Exception calling ".ctor" with "2" argument(s): "session not created: No matching capabilities found (SessionNotCreated)"