Junior — Middle
How can you ensure waiting for a specific element to appear on a web page before proceeding with further actions?
sobes.tech AI
Answer from AI
To wait for a specific element to appear on a web page, explicit waits are usually used. In Selenium WebDriver, for example, you can use the WebDriverWait class along with ExpectedConditions to wait until the element becomes visible, clickable, or appears in the DOM.
Example in Java:
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("elementId")));
// You can then interact with the element
This approach helps avoid errors related to the element not being loaded yet or not being available for interaction.