gpt4 book ai didi

c# - 路径错误visual studio Selenium WebDriver

转载 作者:行者123 更新时间:2023-11-30 23:23:44 24 4
gpt4 key购买 nike

我正在尝试运行一个简单的程序,但出现以下错误:

An unhandled exception of type 'OpenQA.Selenium.WebDriverException' occurred in WebDriver.dll

Additional information: Cannot find Firefox binary in PATH or default install locations. Make sure Firefox is installed. OS appears to be: Vista

代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;

namespace selenium
{
class Program
{
static void Main(string[] args)
{
IWebDriver driver = new FirefoxDriver();

driver.Navigate().GoToUrl("http://www.reuters.com");
driver.Manage().Window.Maximize();

IWebElement searchInput = driver.FindElement(By.XPath("//html/body/div[10]/div[3]/div/td[1]"));
searchInput.GetAttribute("value").ToString();

driver.Close();

}
}
}

我检查了环境变量,路径中有以下内容:

PATH=C:\Program Files\Mozilla Firefox\firefox.exe

我目前正在运行 Windows 10、Visual Studio 2015 和 selenium Webdriver 2.53.0

最佳答案

无法在 PATH 中找到 firefox 二进制文件。确保安装了 firefox C# 解决方案。

var opt = new FirefoxOptions
{
BrowserExecutableLocation = @"c:\program files\mozilla firefox\firefox.exe"
};
var driver = new FirefoxDriver(opt);

关于c# - 路径错误visual studio Selenium WebDriver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38195243/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com