【问题标题】:Unable to check for availability of any element removing hardcoded delay无法检查移除硬编码延迟的任何元素的可用性
【发布时间】:2018-10-18 16:02:04
【问题描述】:

我在 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

【问题讨论】:

  • 见:stackoverflow.com/questions/36590274/…。看起来您可以在那里尝试的方法很少。
  • 感谢@Ryan Wildry 的评论。问题是explicit wait 在与 selenium 结合使用其他语言时有一些选项,但在vba 的情况下,我怀疑是否有任何选项。至少我找不到任何地方。

标签: vba excel selenium web-scraping selenium-chromedriver


【解决方案1】:

似乎已经找到了解决方案。 the link 通向 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-28
    • 1970-01-01
    • 1970-01-01
    • 2018-03-31
    • 1970-01-01
    • 2014-08-08
    • 2019-06-21
    相关资源
    最近更新 更多