2

I've been trying to fix an ElementClickInterceptedException but my methods are not working. This is the Link I am using. When I click on the bars on the left side, before the game time, it opens something like a pop-up but it's on the same Window as shown in the picture... enter image description here I am able to get the information needed on the page. Problem is after i close it by clicking on the x, it won't loop into the next one, it gives me the ElementClickInterceptedException: Message: Element is not clickable at point because another element obscures it. Mostly it does this on the second loop, but sometimes it passes the second and goes to the third but it's never passed the third loop. I tried using the wait and until but that didn't do any help, it only goes to Timeout. Here is the code I'm using for that.

#This fetch all the games I want to scrape for into a list of selenium objects
v1 = _.find_elements_by_class_name('trOddsSection')
driver.implicitly_wait(10)
for __ in v1:
driver.implicitly_wait(10)
    
#__.find_element_by_class_name("col-0").click()
    
    
wait.until(EC.element_to_be_clickable((By.XPATH, ".//td[@class='col-0']")))
yyy = __.find_element_by_xpath(".//td[@class='col-0']")

# This click gets the pop-up thing out
yyy.click()
    
v3 = wait.until(EC.presence_of_element_located((By.CLASS_NAME, "divStatisticsWidget")))
    

sleep(3)

try:
    driver.implicitly_wait(10)
    
    # This is where I scrape what I want from the pop-up
    a = v3.find_element_by_xpath(".//div[@id='right-container']/div[@id='content_headToHead']/div[@class='sectionFound']/div[@class='teamWinsDraws']")
    hm = a.find_element_by_xpath(".//div[@class='teamHomeWins']/span[@class='teamName']/span[@class='resultsPerc']").text
    dr = a.find_element_by_xpath(".//div[@class='teamDraws']/span[@class='teamName']/span[@class='resultsPerc']").text
    aw = a.find_element_by_xpath(".//div[@class='teamAwayWins']/span[@class='teamName']/span[@class='resultsPerc']").text
    print("Here:\t\t{}\t{}\t{}".format(hm, dr, aw))
    driver.implicitly_wait(10)
        
    a_ = v3.find_element_by_xpath(".//div[@id='right-container']/div[@id='content_headToHead']/div[@class='sectionFound']/div[@class='headToHeadHistory']")
    a__ = a_.find_elements_by_xpath(".//table/tbody/tr/td[@class='score']")
        print("H2H {}".format(a__[0].text))
        
except(NoSuchElementException):
    print("teamWinDraws class not found")

# This is where I close the pop-up window so I can move to next    
try:
    driver.implicitly_wait(10)
    sleep(4)
       
    wait.until(EC.element_to_be_clickable((By.XPATH, ".//*[@class='close-icon']")))
    g_g = driver.find_element_by_xpath(".//*[@class = 'close-icon']")
    driver.execute_script("arguments[0].click();", g_g)
except(NoSuchElementException):
    print('close-icon not found')
except(TimeoutException):
    print('Timed out')

Anyone sees something I'm doing wrong or how to maneuver around this please let me know.

0

1 Answer 1

2

Problem Explanation

I see that, you are using driver.implicitly_wait(10) quite a lot in your script, this is basically an implicit wait, which one should set for one time, and it will be in effect till driver is not killed by internal/external way.

So, basically you can keep one driver.implicitly_wait(10) in your entire script, and remove all of them .

Also, we have to keep in mind that based on each row we should define the close button. I have made those corrections below.

Solution

Code :-

driver = webdriver.Chrome(driver_path)
driver.maximize_window()
driver.implicitly_wait(50)
driver.get("https://www.betking.com/sports/s/event/p/soccer/england/eng-premier-league/0/0")
wait = WebDriverWait(driver, 20)
try:
    wait.until(EC.element_to_be_clickable((By.ID, "cookieBoxClose"))).click()
except:
    pass

all_rows = driver.find_elements(By.XPATH, "//tr[contains(@class, 'trOddsSection')]")
j = 0
for row in range(len(all_rows)):
    elements = driver.find_elements(By.XPATH, "//tr[contains(@class, 'trOddsSection')]")
    time.sleep(2)
    elements[j].find_element_by_xpath(".//td[@class='col-0']").click()
    time.sleep(2)
    v3 = wait.until(EC.visibility_of_element_located((By.XPATH, "//div[contains(@id, 'StatisticsWidget')]")))
    try:
        a = v3.find_element_by_xpath(".//div[@id='right-container']/div[@id='content_headToHead']/div[@class='sectionFound']/div[@class='teamWinsDraws']")
        hm = a.find_element_by_xpath(".//div[@class='teamHomeWins']/span[@class='teamName']/span[@class='resultsPerc']").text
        dr = a.find_element_by_xpath(".//div[@class='teamDraws']/span[@class='teamName']/span[@class='resultsPerc']").text
        aw = a.find_element_by_xpath(".//div[@class='teamAwayWins']/span[@class='teamName']/span[@class='resultsPerc']").text
        print("Here:\t\t{}\t{}\t{}".format(hm, dr, aw))

    except:
        print("teamWinDraws class not found")
        pass

    try:
        time.sleep(4)
        elements[j].find_element(By.XPATH, ".//following-sibling::tr//div[contains(@ng-click,'closeStatisticsBetradar')]").click()
        j = j + 1
    except NoSuchElementException:
        print('close-icon not found')
    except TimeoutException:
        print('Timed out')

Imports : -

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

Program output :

Here:       5 (20%) 6 (24%) 14 (56%)
Here:       10 (59%)    6 (35%) 1 (6%)
Here:       5 (33%) 4 (27%) 6 (40%)
Here:       8 (29%) 4 (14%) 16 (57%)
Here:       33 (61%)    14 (26%)    7 (13%)
Here:       12 (29%)    10 (24%)    19 (46%)
Here:       11 (33%)    12 (36%)    10 (30%)
Here:       28 (52%)    13 (24%)    13 (24%)
Here:       6 (23%) 4 (15%) 16 (62%)
Here:       7 (50%) 1 (7%)  6 (43%)
Here:       13 (45%)    8 (28%) 8 (28%)
Here:       5 (50%) 2 (20%) 3 (30%)
Here:       2 (11%) 3 (17%) 13 (72%)
Here:       17 (63%)    3 (11%) 7 (26%)
Here:       20 (59%)    7 (21%) 7 (21%)
Here:       10 (34%)    4 (14%) 15 (52%)
Here:       19 (37%)    19 (37%)    13 (25%)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.