Issue
Good evening,
Please refer to the following webpage: https://prolineplus.olg.ca/en-ca/event/?e177405-Basketball-NBA-USA-Miami-Heat-Chicago-Bulls
I have two functions to click on either the Chicago bulls or Miami Heat as seen on the webpage from the link above. Can you please help me figure out why my current code is no longer clicking on either? I need to be able to use the team variable as the names will constantly change.
I greatly appreciate your help and will upvote/credit those who contribute to the solution!
Main:
driver = startup_login('https://prolineplus.olg.ca/en-ca/event/?e177405-Basketball-NBA-USA-Miami-Heat-Chicago-Bulls')
team = "Chicago"
proline_go_to_match2(driver,team)
Functions:
def proline_go_to_match2(driver, team):
#print(team)
try:
match = WebDriverWait(driver, 15).until(
EC.presence_of_element_located((By.XPATH, "//ul[@class='fdjgs-markets']/li[@class='fdjgs-market']//ul[@class='fdjgs-outcomes']//descendant::li[1]//span[@class='fdjgs-outcome-wrapper' and contains(@aria-label, '"+ team +"')]/span[starts-with(., '"+ team +"')]")) )
match.click()
except:
driver.quit()
def proline_go_to_match3(driver, team):
#print(team)
try:
match = WebDriverWait(driver, 15).until(
EC.presence_of_element_located((By.XPATH, "//ul[@class='fdjgs-markets']/li[@class='fdjgs-market']//ul[@class='fdjgs-outcomes']//descendant::li[2]//span[@class='fdjgs-outcome-wrapper' and contains(@aria-label, '"+ team +"')]/span[starts-with(., '"+ team +"')]")) )
match.click()
except:
driver.quit()
Solution
Check for consent and click on that if exists. use python format() function to change the parameter. Use js executor to click else will get element intercepted error you can use actionchain as well.
driver.get("https://prolineplus.olg.ca/en-ca/event/?e177405-Basketball-NBA-USA-Miami-Heat-Chicago-Bulls")
wait=WebDriverWait(driver,20)
#check for consent
try:
wait.until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Continue']"))).click()
except:
pass
team="Chicago"
items=wait.until(EC.visibility_of_all_elements_located((By.XPATH, "//span[contains(@aria-label, '{0}')]//span[starts-with(., '{0}')]".format(team))))
for item in items:
driver.execute_script("arguments[0].click();", item)
print("Button clicked")
Answered By - KunduK
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.