Home > Net >  ElementClickInterceptedException Error won't fix
ElementClickInterceptedException Error won't fix

Time:01-12

Ok this is a bit embarrassing because I've asked a similar question on here sometime ago, but I tried the suggested solution ie (wait till element clickable), but it didn't work. So here's my code snipped.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import ElementClickInterceptedException, ElementNotInteractableException, TimeoutException, WebDriverException, NoSuchElementException
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from time import sleep
import re
import pandas as pd


def get_links(link):

    driver = webdriver.Firefox()
    driver.get(link)
    driver.implicitly_wait(50)
    sleep(5)

    _flag = True
    knt = 0
    while _flag:
        try:
        
            WebDriverWait(driver, 50).until(EC.invisibility_of_element((By.XPATH, "//a[contains(class='ot-buttons-fw')]")))
            WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='event__more event__more--static']")))
        
            driver.find_element_by_xpath("//*[contains(text(), 'Show more matches')]").click()
            print("works here!")
            print("clicked....................................")
            sleep(5)
            _flag = True
            #tmp = driver.find_elements_by_xpath("//span[contains(text(), 'NBA - Pre-season')]")
            #if len(tmp) > 0:
                #print("Found them!")
                #_flag = False
            if knt > 5: # For testing
                print("Nuff clicked")
                _flag = False
        except(ElementNotInteractableException):
            print("Error!")
            _flag = False
        
    driver.close()
    return None

link = "https://www.flashscore.com/basketball/usa/nba/results/"

_ = get_links(link)

For some reason I keep getting an ElementClickInterceptedException Error at the driver.find_element_by_xpath("//*[contains(text(), 'Show more matches')]").click() line. Any help can do please

CodePudding user response:

Your element overlap with other element, it cause the ElementClickInterceptedException error appear.

Before perform you code, please close the cookies popup with this code snippet:

def get_links(link):

    driver = webdriver.Firefox()
    driver.get(link)
    driver.implicitly_wait(50)
    sleep(5)

    #here, close popup
    if(len(driver.find_elements_by_id('onetrust-accept-btn-handler'))>0):
        driver.find_element_by_id('onetrust-accept-btn-handler').click()

    _flag = True
    knt = 0
    while _flag:
        ....
        ....

And remove this line:

WebDriverWait(driver, 50).until(EC.invisibility_of_element((By.XPATH, "//a[contains(class='ot-buttons-fw')]")))

This is invalid xpath expression, and no needed, have handled by if(popup accept) condition the above.

  • Related