代码之家  ›  专栏  ›  技术社区  ›  SIM

无法检查删除硬编码延迟的任何元素的可用性

  •  0
  • SIM  · 技术社区  · 6 年前

    我已经在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
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   SIM    6 年前

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