New to coding so I’m at a bit of a loss here. So I’m trying to build a script which loops until a button (add to basket) is clickable. This full step by step list on how I wish the script to go is
- Start loop.
- Check if button is clickable.
- If it is not clickable then refresh the page and go back to step 2.
- If button is clickable then click it
- If the button has been clicked, wait 5 seconds and check if a specific element has been found. If this element has not been found then refresh the page and go back to step 2
- If element is present then sent telegram notification and break.
I have coded the first 4 steps which is below:
while True:
try:
WebDriverWait(driver, 1).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.areas-filter-panel__find-button"))).click()
except TimeoutException:
driver.refresh()
continue
I just need a helping hand in coding the last two steps. The specific element I’m looking for is on a different page to the button I want to be clicked (eg: the checkout page). This element is: ctl00$body$CountDown_timerMessage
Essentially I need the script to detect the presence of this element as sometimes the button becomes clickable, the script clicks the button but someone has already beaten me to this item; the item then can’t be put into my basket but the current script I have stopped when the button becomes clickable. I need the script to make sure the webpage is the checkout page.
I have then coded a telegram message to alert me that the item is in my basket
telegram_send.send(messages=["TICKET IN BASKET"])