I am very much not experienced in coding and all my work here is done by research.
I am creating a python script which helps me add a ticket to basket via selenium however coming across some things im not sure how to do.
The ticketing website requires to sit and refresh the page until a ticket becomes available from another user and then a button becomes clickable which then allows you to reserve it.
I have created the 1st part of the script which opens up and link and click the button when its available however when its not available i need to page to refresh and attempt to click the button if available and repeat until hopefully succesful which by that point the script can stop.
When a ticket is added to basket the URL changes so that could be a condition for the script to check before stopping.
Below is the python code which contains the URL link where the button is not clickable.
To test the script working change the URL to this: https://ticketing.liverpoolfc.com/en-GB/events/liverpool%20women%20v%20everton%20women/2022-9-25_18.45/anfield?hallmap
The button that needs to be clicked is CHOOSE SEAT FOR ME
from selenium.webdriver.common.keys import Keys
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
PATH = "D:\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("https://ticketing.liverpoolfc.com/en-GB/events/liverpool%20v%20newcastle%20united/2022-8-31_20.00/anfield?hallmap")
try:
element = WebDriverWait(driver, 25).until(
EC.element_to_be_clickable((By.XPATH,"/html/body/div[7]/div/button"))
)
finally:
print("Page loaded")
button = driver.find_element(By.XPATH, "/html/body/div[7]/div/div[4]/div[1]/div[3]/div[2]/div[2]/div/div[3]/div[1]/button[2]")
button.click()```