Selenium Webdriver(VBA):显式等待

编程入门 行业动态 更新时间:2024-10-28 10:36:50
本文介绍了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):显式等待

本文发布于:2023-11-08 10:43:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1569169.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Selenium   Webdriver   VBA

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!