Selenium Webdriver(VBA):显式等待 [英] Selenium Webdriver (VBA): Explicit Wait

查看:405
本文介绍了Selenium Webdriver(VBA):显式等待的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在浏览一个Web应用程序,如果尝试单击某个元素之后才能与之交互,则该Web应用程序通常会引发错误.

I am navigating a web application that will often throw an error if there is an attempt to click an element before it can be interacted with.

使用Selenium WebDriver(java)时,我可以轻松解决此问题:

When using Selenium WebDriver (java), I can easily work around the problem:

 WebDriverWait wait = new WebDriverWait(driver, 15);

 wait.until(ExpectedConditions.elementToBeClickable(By.id("element")));

但是,我试图使用Selenium类型库在VBA中编写脚本,尽管尝试了许多不同的方法,但我唯一的成功是:

However, I am trying to write the script in VBA utilizing the Selenium type library, and, despite trying numerous different ways, the only success I am having is:

webdriver.wait

告诉我,如果可能的话,应该避免使用

.如果有人可以建议如何将Java转换为VBA或提供任何其他解决方案,我将不胜感激.

which I have been told should be avoided if at all possible. If someone can advise how to translate my java into VBA, or provide any other solution, I would be extremely grateful.

推荐答案

VBA的硒插件是非官方的,不支持此功能.

The selenium plugin for VBA is unofficial and doesn't support this feature.

您可以通过使用onError重试产生错误的操作,直到成功或超时,来解决此问题:

You can work around this by using onError to retry the action that is producing an error until it succeeds or times out:

Sub test
    OnError GoTo Retry
        webDriver.findElementById("element")
    Exit Sub

    Dim i as integer
    :Retry
        webDriver.Wait(500)
        i = i + 1
        if i = 20 then onerror go to 0
    Resume
end sub

这篇关于Selenium Webdriver(VBA):显式等待的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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