Waits¶
Using wait methods you will be able to synchronize parts of the process waiting for something before performing a certain action.
Wait¶
You can make the process wait/sleep for an interval of time in milliseconds.
Waiting for Files¶
In addition to waiting for process situations, you can also wait for some files. These methods can be useful when you need to wait for a file to be saved or available on disk.
Wait for File¶
If you have the path of a specific file, you can use it directly in the wait method.
Wait for New File¶
In cases where you don't have or don't know the specific path of the file, you can use the wait method based on the file extension.
Wait for Downloads¶
You can wait until all the downloads are finished before closing the browser or proceeding with your automation steps.
Wait for New Page¶
In cases where a new page opens, you can do a treatment to wait for this page properly before proceeding with the process.
# Starting the process.
bot.browse("https://documentation.botcity.dev/")
print("Opening a new page")
# Using the method as a context manager.
with bot.wait_for_new_page(waiting_time=10000, activate=True):
# The code inside the 'with' context will be responsible for opening a new page.
btn_new_page = bot.find_element('/html/body/div[3]/nav/div/ul/li[5]/a', By.XPATH)
btn_new_page.click()
# When exiting the 'with' block the new page is already loaded and activated.
print("New page open, continuing the process...")
// Starting the process.
browse("https://documentation.botcity.dev/");
System.out.println("Opening a new page");
// Passing the code block responsible for opening the new page.
waitForNewPage(true, 10000, new Runnable() {
@Override
public void run() {
WebElement btnNewPage = findElement(By.xpath("/html/body/div[3]/nav/div/ul/li[5]/a"));
btnNewPage.click();
}
});
System.out.println("New page open, continuing the process...");
Wait for Element Visibility¶
You can wait until an element is visible or hidden on the page.
Wait for Stale Element¶
In addition, it is also possible to wait until the element becomes stale (outdated).