简体   繁体   English

将C#转换为Powershell

[英]Translate C# to Powershell

I'm trying to setup Firefox WebDrvier to automate the navigation with PowerShell. 我正在尝试设置Firefox WebDrvier以使用PowerShell自动进行导航。 I can launch it using: 我可以使用以下命令启动它:

# Load the Selenium .Net library
Add-Type -Path "net40\WebDriver.dll"

# Set the PATH to ensure geckodriver.exe can found
$env:PATH += ";E:\*****\FirefoxDriver"

$driver = New-Object OpenQA.Selenium.Firefox.FirefoxDriver

But I need to use the service "FirefoxDriver Service ". 但是我需要使用服务“ FirefoxDriver Service ”。 I found this C# code on the Internet . 在Internet上找到了此C#代码。

FirefoxDriverService service = FirefoxDriverService.CreateDefaultService();
service.FirefoxBinaryPath = @"C:\Path\to\your\FF\exe.exe";
FirefoxOptions options = new FirefoxOptions();
options.AddAdditionalCapability(CapabilityType.AcceptSslCertificates, true);
TimeSpan t = TimeSpan.FromSeconds(10);

Driver = new FirefoxDriver(service, options, t);

I tried some experiments (in PowerShell): 我尝试了一些实验(在PowerShell中):

1 1

[FirefoxDriverService]$service = $FirefoxDriverService.CreateDefaultService()

But Powershell said this to me: 但是Powershell对我说:

 You cannot call a method on a null-valued expression.

2 2

$driver = New-Object OpenQA.Selenium.Firefox.FirefoxDriver(service FirefoxDriverService)

But Powershell said this to me: 但是Powershell对我说:

 No Service Found For Given Name

I am a sysadmin not a developer, so I have no more ideas. 我不是系统管理员,也不是开发人员,所以我没有其他想法了。

Here is the doc about the webdriver for Firefox . 这是有关Firefox Web驱动程序文档

CreateDefaultService()是静态方法,请使用静态成员运算符::

$Service = [OpenQA.Selenium.FirefoxFirefoxDriverService]::CreateDefaultService()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM