import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.support.ui.ExpectedConditions;
import java.time.Duration;
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
List<WebElement> spanElement = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[contains(text(),'Updated Text')]")));
System.out.println("spider: " + counts.get(0).getText());
System.out.println("amazon: " + counts.get(1).getText());
output :
spider: 645
amazon: 27836
You can also use other ExpectedConditions based on the action you need to perform:
elementToBeClickable()- It will Wait for the element to be visible and enabled.
presenceOfElementLocated() - It will Wait for the element to be present in the DOM.