我正在浏览一个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):显式等待
发布评论