Vrtgs / thirtyfour

Selenium WebDriver client for Rust, for automated testing of websites
Other
1.05k stars 77 forks source link

Is there a way to use wait_until or something like it to way for a specific ID to be available ? #186

Closed patrickelectric closed 6 months ago

patrickelectric commented 11 months ago

I have a dynamic page that I don't know how long will it take to show the button, sometimes is 1 second, sometimes 4 seconds. I don't want to wait forever each time for me to click. Is there a way to wait for it without a loop ?

stevepryde commented 11 months ago

If you're waiting for the element to become visible you can do something like this:

let elem = driver.query(By::Id("button1")).first().await?;
// Wait until the element is displayed.
elem.wait_until().displayed().await?;

From the example at https://docs.rs/thirtyfour/latest/thirtyfour/extensions/query/struct.ElementWaiter.html

If the button doesn't even exist on the page but you want to wait for it to show up, this is the default behaviour when using the ElementQuery trait. See https://docs.rs/thirtyfour/latest/thirtyfour/extensions/query/struct.ElementQuery.html

patrickelectric commented 6 months ago

Thnaks @stevepryde!