jwalman
jwalman

Reputation: 265

Selenium ChromeDriver - Element is not clickable

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

Upvotes: 1

Views: 245

Answers (2)

chitown88
chitown88

Reputation: 28565

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]

Upvotes: 0

undetected Selenium
undetected Selenium

Reputation: 193108

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

Upvotes: 1

Related Questions