Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.9k views
in Technique[技术] by (71.8m points)

excel - Selenium Webdriver (VBA): Explicit Wait

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.

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")));

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You might try looping until the element has been set correctly with a time out to ensure you can't go into an infinite loop. The danger with the accepted answer is there is no way to escape the loop if not found.

Dim t As Date, ele As Object
t = Timer
Do
    DoEvents
    On Error Resume Next
    Set ele = .FindElementById("element")
    On Error GoTo 0
    If Timer - t = 10 Then Exit Do '<==To avoid infinite loop
Loop While ele Is Nothing

Note: User @florentbr wrote a js wait clickable function to be executed via Selenium Basic. Example in this SO answer.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...