excel - 找不到 div 类时出现“内存不足”错误
问题描述
我正在将 Selenium 与 ChromeDriver 一起使用
Dim driver As New ChromeDriver
driver.Get "https://somewebsite.com"
val = driver.FindElementByCss(".some-class-that-does-not-exist-on-this-page").Text
Cells(x, 2).Value = val
当我的 vba 代码在页面上找不到该类时,它会抛出一个
“内存不足”错误 7
即使,我的任务经理说我的记忆力只有 29%。
当我单击帮助时,它会将我带到https://docs.microsoft.com/en-us/office/vba/Language/Reference/User-Interface-Help/out-of-memory-error-7
我已经尝试过那里建议的事情:
但问题仍然存在。只有在找不到 div 类时才会发生这种情况。
我试图添加一个 if 语句来检查元素是否存在
If IsObject(driver.FindElementByCss(".some-class-that-does-not-exist-on-this-page")) Then
val = driver.FindElementByCss(".some-class-that-does-not-exist-on-this-page").Text
Cells(x, 2).Value = val
End If
但仍然导致内存不足错误。
解决方案
我通过使用错误处理程序解决了它
On Error GoTo ErrorHandler
elem = driver.FindElementByCss(".some-class-that-does-not-exist-on-this-page")
Cells(x, 2).Value = elem.Text
ErrorHandler:
Cells(x, 2).Value = "HTML element not found"
Resume Next
推荐阅读
- openid-connect - 确保在身份提供商处注销 - Azure AD b2c、OIDC
- windows - 无法将现有 WSL1 发行版转换为 WSL2
- javascript - 如何替换字符串中 [] 内的文本?
- php - 将数据从 php/mysql 传递到颤振小部件
- spring - 使用许多参数(过滤器)创建 GET 方法的最佳实践
- javascript - 尽管有不同的调用,vue 组件的一部分永远不会改变
- android - 如何将 onClick 事件从父级传递给子级?
- java - 在什么情况下,Maven Dependency Analyzer 的编译范围内有不同版本的依赖关系?
- jmeter - JMeter 中的 JSON 断言失败
- r - 如何检查数据框的每个元素的 NA 并单独打印它们的位置(而不是作为向量)