vba - 无法检查移除硬编码延迟的任何元素的可用性
问题描述
我在 vba 中编写了一个与 selenium 相关的脚本,以在某些 torrent 站点中启动搜索。我的脚本运行良好,但问题是我必须hardcoded delay
在脚本中使用才能使其成功。我现在想做的是通过从我的脚本中剔除硬编码延迟来使用某个循环或任何一种循环来检查所需元素的可用性。对此的任何帮助将不胜感激。
这是我迄今为止的尝试(工作之一):
Sub SearchItem()
With New ChromeDriver
.get "https://torrentz2.eu/"
Application.Wait Now + TimeValue("00:00:10") ''I wish to shake this hardcoded delay off
.FindElementByCss("#thesearchbox").SendKeys ("Udemy")
.FindElementByCss("#thesearchbutton").Click
End With
End Sub
参考添加:
Selenium Type Library
解决方案
似乎已经找到了解决方案。有指向github的链接Florent B.
提供了一个很好的解决方案,说明脚本应该如何等待所需的元素可用。
脚本应该是这样的:
Sub SearchItem()
With New ChromeDriver
.get "https://torrentz2.eu/"
.FindElementByCss("#thesearchbox", timeout:=10000).SendKeys "Udemy" ''wait for the element upto 10 seconds
.FindElementByCss("#thesearchbutton").Click
End With
End Sub
推荐阅读
- php - 连接行返回数组内爆错误
- python - scipy.io.mmread 无法读取 .mtx 文件
- python - 我如何将这两个球变成许多球?
- angular - Angular 6 vendor.js 文件太大
- javascript - 参数“TabsCtrl1”不是函数,未定义
- javascript - 在织物 js 画布上加载 svg 不显示圆形
- c# - 添加 HttpClientFactory 导致 cancelTokenSource 错误
- powershell - Where-Object 优化 Powershell
- android-studio - 如何运行 Dart 临时文件?似乎没有运行选项
- amp-analytics - AMP-Linker - 脚本标签包含无法解析的无效 JSON