When I load a webpage, the text I need appears with a delay. First, there are three points instead, after some time the text itself appears.
Waiting via WebDriver wait does not work.

What you see immediately when the page loads:
Al. post office: ...
What is loaded a little later and, in fact, I need:
Al. Email: tram-param@gde-to.tut

private final WebDriverWait wait = new WebDriverWait(DriverSingleton.getDriver(), 10); private final WebElement companyEmail = wait.until( ExpectedConditions.visibilityOfElementLocated(By.xpath("//li[contains(text(),'Эл. почта:')]"))); 

Through Assert I check the received text (email) with a regular expression. The test, of course, feilitsya, because I do not get a valid email.
Tell me how to wait for the item to load.

  • found out that the site actually has protection from bots, I don’t understand how to get around it - me3RR0R Ac

1 answer 1

Waiting for you to work, you are waiting for the li tag, and you have it in the markup immediately when the page loads. As an option to use a method that would check the current value in the loop and as long as it is equal, in your case, the "..." cycle would not end.

I will write in C #, I think you will not be able to write to Java.

 private void TestMethod() { ... var selector = By.Id("email"); WaitElementChangeText(selector, "...", 15); ... } private static void WaitElementChangeText(By selector, string text, int maxWaitSeconds) { var element = _driver.FindElement(selector); // Берем текущую дату и добавляем таймаут - это максимальное время ожидания var maxDate = DateTime.Now.AddSeconds(maxWaitSeconds); // Обновляем значение элемента, пока оно эквивалетно переданному ("...") и проверяем время while (element.Text.Equals(text) && maxDate.Ticks > DateTime.Now.Ticks) { element = _driver.FindElement(selector); } }