无法检查任何消除硬编码延迟的元素的可用性 [英] Unable to check for availability of any element removing hardcoded delay

查看:61
本文介绍了无法检查任何消除硬编码延迟的元素的可用性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在vba中与硒相关联地编写了一个脚本,以开始在某些洪流站点中进行搜索.我的脚本运行良好,但问题是我必须在脚本中使用hardcoded delay才能使其成功.我现在想做的是通过一些循环或任何类似的方式通过从脚本中排除硬编码的延迟来检查所需元素的可用性.在这方面的任何帮助将不胜感激.

I've written a script in vba in association with selenium to initiate a search in some torrent site. My script is doing fine but the problem is I had to use hardcoded delay within my script to make it successful. What I wish to do now is check for the availability of desired element using some loop or any of that sort by kicking out hardcoded delay from my script. Any help on this will be highly appreciated.

到目前为止,这是我的尝试(正在工作):

This is my attempt so far (working one):

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.为脚本应如何等待,直到所需元素可用.

Seems to have found the solution already. There is the link leading to github where Florent B. has provided an excellent solution as to how the script should wait until the desired element is available.

这应该是脚本的样子:

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

这篇关于无法检查任何消除硬编码延迟的元素的可用性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆