您如何使用Powershell在硒中定义Firefox exe路径?

时间:2019-04-09 17:09:15

标签: powershell selenium-webdriver

我试图将Firefox硒与Firefox配合使用,并且我需要指定Firefox的可执行文件(便携式Firefox)。我可以使脚本与chrome一起使用,并且找到了如何指定chrome的路径,但是我对Firefox并不满意。 这是我到目前为止所获得的一切:

# Website and credential variables
$YourURL = "http://192.168.0.1/" # Website we'll access

# Invoke Selenium into our script!
# Geckodriver.exe
$env:PATH += ";D:\Powershell\webdriver" 
Add-Type -Path "D:\Powershell\webdriver\WebDriver.dll" 
Add-Type -Path "D:\Powershell\webdriver\WebDriver.Support.dll" 


$ff_object = New-Object "OpenQA.Selenium.Firefox.FirefoxDriver" 

1 个答案:

答案 0 :(得分:0)

非常感谢JimEvans!这是我的Powershell工作代码:

$YourURL = "http://192.168.0.1/" # Website we'll access

$env:PATH += "C:\Users\Carl\Desktop\webdriver\" # Adds the path for ChromeDriver.exe to the environmental variable 
Add-Type -Path "C:\Users\Carl\Desktop\webdriver\WebDriver.dll" # Adding Selenium's .NET assembly (dll) to access it's classes in this PowerShell session

$FirefoxOptions = New-Object OpenQA.Selenium.Firefox.FirefoxOptions
$FirefoxOptions.BrowserExecutableLocation = "D:\PortableApps\FirefoxPortable\App\Firefox64\firefox.exe"
$FirefoxDriver = New-Object OpenQA.Selenium.Firefox.FirefoxDriver($FirefoxOptions) 

# Make use of Selenium's class methods to manage our browser at will
$FirefoxDriver.Navigate().GoToUrl($YourURL) # Browse to the specified website