gpt4 book ai didi

c# - 使用 chrome 驱动程序查找元素

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

我正在使用驱动程序 chrome 以编程方式点击按钮,但我无法访问 chrome.exe

static IWebDriver driverchromeDriver;
public void chromeDriver()
{
driverchromeDriver = new ChromeDriver(@"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe");
driverchromeDriver.Navigate().GoToUrl("http://www.google.com");
driverchromeDriver.FindElement(By.Id("lst-ib")).SendKeys("qwe");
driverchromeDriver.FindElement(By.Id("lst-ib")).SendKeys(OpenQA.Selenium.Keys.Enter);
}

但它显示了这个问题:附加信息:文件 C:\Program Files (x86)\Google\Chrome\Application\chrome.exe\chromedriver.exe 不存在。可以在http://chromedriver.storage.googleapis.com/index.html 下载驱动程序。

最佳答案

显然,它需要一个名为“chromedriver.exe”的文件,该文件位于您在构造函数中指定的目录中。 “chromedriver.exe”似乎是硬编码在 ChromeDriver 中。如果您通过提供的链接下载 chromedriver.exe,并将代码更改为:

driverchromeDriver = new ChromeDriver(@"path where chromedriver.exe is located");

它应该可以工作。

附带说明:chromedriver.exe 与 Chrome 不同。 Chrome 是实际的浏览器,chromedriver.exe 是用于自动测试的实际 WebDriver。所以我不会将 chromedriver.exe 放在与 Chrome 相同的目录中。

关于c# - 使用 chrome 驱动程序查找元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45105311/

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