首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在使用Powershell的selenium中定义firefox exe路径?

如何在使用Powershell的selenium中定义firefox exe路径?
EN

Stack Overflow用户
提问于 2019-04-10 01:09:15
回答 1查看 732关注 0票数 0

我正在尝试将selenium Firefox与powershell一起使用,并且我需要指定firefox的可执行文件(可移植firefox)。我可以让我的脚本在chrome上工作,而且我已经找到了如何指定chrome的路径,但我在Firefox上就没那么走运了。到目前为止,我得到的信息如下:

代码语言:javascript
复制
# 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" 
EN

回答 1

Stack Overflow用户

发布于 2019-04-11 07:59:28

非常感谢JimEvans!下面是我的powershell工作代码:

代码语言:javascript
复制
$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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55597943

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档