Home > Back-end >  Selenium ChromeDriver - Element is not clickable
Selenium ChromeDriver - Element is not clickable

Time:04-07

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: enter image description here

CodePudding user response:

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

CodePudding user response:

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]
  • Related