2
我試圖設置Firefox WebDrvier以使用PowerShell自動導航。我可以用啓動它:將C#翻譯爲Powershell
# 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
但我需要使用的服務「FirefoxDriver 服務」。我發現這個C#代碼on the Internet。
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);
我嘗試了一些實驗(在PowerShell中):
[FirefoxDriverService]$service = $FirefoxDriverService.CreateDefaultService()
但Powershell的說,這對我說:
You cannot call a method on a null-valued expression.
$driver = New-Object OpenQA.Selenium.Firefox.FirefoxDriver(service FirefoxDriverService)
但Powershell的說,這對我說:
No Service Found For Given Name
我是一個系統管理員不是開發者,所以我沒有更多的想法。
這是doc about the webdriver for Firefox。