excel - 接收 KeyNotFoundError 字典键未找到:使用 .click 方法时的状态
问题描述
我目前正在尝试在 Excel 中学习 VBA,并且我编写了一个简单的程序,我应该能够启动 Chrome 并单击一个按钮。问题是我得到一个运行时错误'0':KeyNotFoundError Dictionary key not found:status每当我尝试使用该.click
方法时。
我从以下站点https://florentbr.github.io/SeleniumBasic/下载了 Selenium Basic,激活了 VBA 中的引用并下载了最新的 chromedriver
Sub driver()
Dim driver As New Selenium.WebDriver
Set driver = New Selenium.WebDriver
driver.Start "chrome"
driver.Get "http://www.google.com"
Set Element = driver.FindElementByName("btnI")
Element.Click
End Sub
这只是我启动 Chrome 并转到 Google 并单击“我感到幸运”按钮的简单代码。
解决方案
最新版本的 Chrome 抛出“KeyNotFoundError Dictionary key not found:status”错误。
尝试用 2.46 版替换您的 Chromedriver。这是链接:https ://chromedriver.storage.googleapis.com/index.html?path=2.46/
下面是我尝试过的代码,它对我来说非常好。让我们知道此解决方案是否适合您!:)
Sub driver()
Dim driver As New Selenium.WebDriver
Set driver = New Selenium.WebDriver
driver.Start "chrome"
driver.Get "http://www.google.com"
driver.FindElementByCss("#tsf > div:nth-child(2) > div > div.FPdoLc.VlcLAe > center > input[type=submit]:nth-child(2)").Click
End Sub
推荐阅读
- java - Spring:在外部添加属性文件
- swift - ARKit:在节点后面放置一个节点
- javascript - 使用(更改)Angular 5 访问数组的每个部分
- c - 结构中相同的 ArrayName 具有不同的 ID
- javascript - 如何在 javascript fetch() 方法上传递带有 url 的变量?
- c - 2D 等距立方体绘制
- swift - 从观察者更新 TableView Cell UI
- visual-studio - Visual Studio 2017 Raspberry Pi Raspbian (Linux) 连接/构建失败
- javascript - 使用 ES6 重构 JSON 对象
- javascript - href 中的多个替换字符串共享同一个类