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

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

问题描述

我正在浏览一个 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 的 selenium 插件是非官方的,不支持此功能.

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天全站免登陆