1

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 div then closes until the next purchase appears in the same div. 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?

At1ll3y
  • 13
  • 2

1 Answers1

0

You can use try and except

while true:
    try:
        WebDriverWait(browser, 30).until(EC.presence_of_element_located((By.CSS_SELECTOR, ".reply-button"))).click()
    except:
        continue
    else:
        break

codester_09
  • 5,622
  • 2
  • 5
  • 27
  • 1
    Yes, but I could happen that there isn't any purchase for 8 hours. Should I add then 28800s to wait? I was hoping for a more elegant way to solve this – At1ll3y Jan 15 '22 at 11:49