Selenium Python: How to wait for div to appear, do stuff, then wait again and so on?

I have a website where I need to automate some actions.

Every time a customer does a purchase, a div with an input and a submit button appears. On that div I need to enter a value and click submit the submit button inside the div. The div then closes until the next purchase comes. Then it appears again and I need to do the same actions, and so on.

It’s indefinite.

I already found some solutions that point to the direction:
Selenium – wait until element is present, visible and interactable

WebDriverWait(browser, 20).until(EC.presence_of_element_located((By.CSS_SELECTOR, ".reply-button"))).click()

But I can’t provide a specific time to wait. I need a solution that keeps going in a loop indefinitely and progress all purchases throughout the day

Every solution that I find solves the problem that the website takes time to load. But I have a completely different problem underlying. I need to wait for a purchases to happen. So I can’t set a specific time to wait. It could be indefinite.

What Selenium function could help me -in a best practice way- with my problem?


Reslant — Collect feedback, assist users, share updates with a forum

Simple and complete Flutter hooks testing utilities that encourage good testing practices