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

标签 c# bots

我正在使用 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/

相关文章:

c# - 如何在不向前移动的情况下从 XmlReader 读取?

node.js - 在 Node.js 机器人服务中实现 Redis

c# - 按 Url 输出缓存(路由)ASP.NET 4

c# - 无法使用 WMI 终止进程,但 taskkill 可以工作

message - 火种 : How to send an automatic message?

javascript - 如何使用 Javascript 保护机器人/爬虫的表单

node.js - Microsoft Bot Framework verify Bot Framework() 始终返回 Forbidden

apache - mod_security 960015 阻止 Google 和其他好的机器人

c# - 为什么 Parallel.For 会执行 WinForms 消息泵,如何防止?

c# - 在 C# 中终止正在运行的进程的替代方法