How to create callback for element appearing Selenium?

Viewed 62

There is an element on page that appears every 2-5 min. I want to click this element as fast as possible when it appears. I think I should use sth like this:

new WebDriverWait(driver, Duration.ofSeconds(10000)).until(ExpectedConditions.elementToBeClickable(By.xpath("xpath"))).click();

And repeat it in infinite loop. But I need to wait this element asynchronously (in current thread I use this WebDriver for other actions), and I want to know how can I correctly do this. I read that WebDriver is not thread-safe, so it's incorrect to create new thread with infinit loop.

I consider it would be ideal to create some kind of callback for appearing of needed element, is it possible?

0 Answers
Related