1

The following site below recently updated their UI and my existing code no longer works for reasons I cannot figure out. My function (proline_go_to_match1) used to select and click on the game using the PARTIAL_LINK_TEXT where I passed the team name. The team name exists in the link however I am getting the error message pasted below. I have included my code snippet and would greatly appreciate if anyone knows why this happening and how to fix it.

Thank you very much!

Website: https://prolineplus.olg.ca/en-ca/event-path/?p23795-NBA

Error message:

"Message: element click intercepted: Element <a href="/en-ca/event/?e109531-NBA-Basketball-USA-Toronto-Raptors-Atlanta-Hawks">...</a> is not clickable at point (415, 697). Other element would receive the click: <div class="cc-content">...</div>"

Code:

def proline_go_to_match1(driver, team):
    try:
        match = WebDriverWait(driver, 15).until(
            EC.presence_of_element_located((By.PARTIAL_LINK_TEXT, team))
        )
        match.click()
    except Exception as e:
        print(e)

proline_driver = webdriver.Chrome()
proline_driver.get('https://prolineplus.olg.ca/en-ca/event-path/?p23795-NBA')

capitalized_team = "TORONTO RAPTORS"
proline_go_to_match1(proline_driver,capitalized_team)

Here I have circled the link I would like click passing "TORONTO RAPTORS"

enter image description here

jwalman
  • 245
  • 2
  • 8

2 Answers2

1

Seems you are close enough.

Instead of presence_of_element_located() you need to induce WebDriverWait for the element_to_be_clickable() and you can use the following locator strategy:

  • Using PARTIAL_LINK_TEXT:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, f"{capitalized_team}"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[contains(., '" +capitalized_team+ "')]"))).click()
    

Update

It's the cookie banner content which blocks your click

cookie_content


Solution

You need to accept the cookies:

driver.get("https://prolineplus.olg.ca/en-ca/event-path/?p23795-NBA")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.cc-btn.cc-dismiss"))).click()
capitalized_team = "TORONTO RAPTORS"
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, f"{capitalized_team}"))).click()

Browser Snapshot:

TORONTO RAPTORS

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thank you for the response I greatly appreciate you taking the time to help me! However I have tried you suggestion and it doesn't seem to work. Can you please show an example of using the XPATH solution in my function? When I try adding match = WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "team"))) match.click() it does not click the link – jwalman Apr 05 '22 at 19:22
  • @jwalman - What's the value you passed in the "team" parameter? – Muhammad Farooq Apr 05 '22 at 20:13
  • @MuhammadFarooq, I passed capitalized_team = "TORONTO RAPTORS" – jwalman Apr 05 '22 at 20:23
  • @jwalman Instead of `team` shouldn't you be passing _`capitalized_team`_? – undetected Selenium Apr 05 '22 at 20:24
  • Yes when I call the function I use the variable capitalized_team which is the variable team within the function. Regardless the value being passed is "TORONTO RAPTORS" – jwalman Apr 05 '22 at 20:34
  • @undetectedSelenium it appears that your code is clicking the container where each game is line and link is stored but not clicking the actual link. On the website when I click the larger container a blue outline is shown. I have added a screenshot to further show the link I am trying to click. Thank you for the help I really appreciate it! – jwalman Apr 05 '22 at 20:35
  • @jwalman Checkout the updated answer and let me know the status. – undetected Selenium Apr 05 '22 at 20:50
  • 1
    @undetectedSelenium Your solution works when I add the code but for some reason does not work when I add it into my function. I am not sure why that is. Can you please update your solution to where it uses the function? This would be wonderful, thank you!! – jwalman Apr 05 '22 at 20:59
  • @jwalman Would love to look into it. Can you raise a new question with all the relevant details? – undetected Selenium Apr 05 '22 at 21:01
  • @undetectedSelenium Please refer to this question my original code snippet utilizes a function where I pass the team name to click the correct link – jwalman Apr 05 '22 at 21:02
0

Not sure if this is of use, but you could get the data from the api as opposed to Selenium:

import requests
import pandas as pd
import re
# pip install choice
import choice


url = 'https://www.online.polg.abpo.io/metal/v3/sportsbookdata/current/events/usview'
headers = {
    'X-LVS-HSToken': '9aBYBhGVpb9NCGAmideXXVg4OOns72-U1tVMKw9vWyFftWb69mYm8TUWzepu-MgXcR1TOjgDJW0x_na5eW9ySoDuV4MsBe8j0N8P-ylZeHt82zVkbB3fNUUYmwV1gUmPxWlGtFi7DZRDMbbLAOJ18g=='
    }
payload = {
    'eventPathIds': '23795',
    'eventsPerPage': '5',
    'pageIndex': '0'}



jsonData = requests.get(url, params=payload, headers=headers).json()

eventData = []
for k, v in jsonData['items'].items():
    if 'e' in k:
        temp_dict = v.copy()
        temp_dict.update({'eventId':k})
        eventData.append(temp_dict)
        
eventIds = {each['desc']:each['eventId'] for each in eventData}
     
game = choice.Menu(list(eventIds.keys())).ask()
eventId = re.search('(\d.*)', eventIds[game]).group(1)



url = f'https://www.online.polg.abpo.io/metal/v3/sportsbookdata/current/events/{eventId}'
payload= {'extraMarkets': 'true'}
jsonData = requests.get(url, params=payload, headers=headers).json()

results_df = pd.json_normalize(jsonData['items'].values())

Output:

Make a choice:
 0: Dallas Mavericks @ Detroit Pistons
 1: Brooklyn Nets @ New York Knicks
 2: Boston Celtics @ Chicago Bulls
 3: Washington Wizards @ Atlanta Hawks
 4: Oklahoma City Thunder @ Utah Jazz

Enter number or name; return for next page

? 2


print(results_df)
               type    parent  ...   teamId  teamDescription
0     EventDataItem    p23795  ...      NaN              NaN
1    MarketDataItem   e110254  ...      NaN              NaN
2    MarketDataItem   e110254  ...      NaN              NaN
3    MarketDataItem   e110254  ...      NaN              NaN
4    MarketDataItem   e110254  ...      NaN              NaN
..              ...       ...  ...      ...              ...
75  OutcomeDataItem  m8985345  ...  20748.0    Chicago Bulls
76  OutcomeDataItem  m8985345  ...  20748.0    Chicago Bulls
77  OutcomeDataItem  m8985345  ...  20748.0    Chicago Bulls
78  OutcomeDataItem  m8985345  ...  20748.0    Chicago Bulls
79  OutcomeDataItem  m8985345  ...  20748.0    Chicago Bulls

[80 rows x 46 columns]
chitown88
  • 27,527
  • 4
  • 30
  • 59