Selenium Wait function does not capture loading element that appears quickly on the screen

Asked

Viewed 44 times

1

I have the following Widget in HTML

<div class="atl-container">
   <div class="ui_active_loader">
     ::before
     ::after
   </div>
</div>

Shown in the following imageTabela de resultados sendo carregada In the official documentation of Selenium there are some options, I tried all but the one that most approximates the expected result was the Fluentwait, in the code below:

_wait = new WebDriverWait(webDriver, timeout: TimeSpan.FromSeconds(30))
{
      PollingInterval = TimeSpan.FromSeconds(1),
};
_wait.IgnoreExceptionTypes(typeof(NoSuchElementException));

Where every 1 second, for 30 seconds he checks the condition of the current element, but I end up getting the following error:

selenium.common.exceptions.NoSuchElementException: Unable to locatet element{"method":"id","selector":"inputSession"}

I am looking for the element via Xpath since it does not have Id, and by error, I understand that it was not possible to find the div in question, since its loading is very fast, but by default I need to know if this Load has been completed to be able to proceed with the automation.

In the place where you are passing a load, a table will appear with the search results. How to force a hold until this Loader element becomes Invisible or Hidden?

1 answer

1


I have never used Selenium for c#, what I will suggest is from a script that I have that might do what you want.

One way to solve is by using the function expected_conditions in combination with the function webDriverWait:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
#códigos de inicialização e definição do url...
url='https://...'
driver = webdriver.Firefox()
driver.get(url)
#códigos para clicar em elementos

WebDriverWait(driver, 10).until(EC.invisibility_of_element((By.ID, "aLoadingBox")))
tabela = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "dtListaEntidade")))

This is a case very similar to yours, after a click on a button, I should expect the html element with id aLoadingBox disappear (a spinner). After it disappears I expect an html table (tag table) with id 'dtListaEntidade' be present in html. From this moment I do scraping (scrapy) of table rows.

I am giving you a general idea of a script that is in Prod. Maybe in C# there is some function equivalent to these that I have in my Python code.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.