Selenium "element click intercepted error "

Question:

url=https://www.hipodromx.com/galop.aspx?Page=1

I want to click on all the tabs in order and print the texts in the tables opened under them to the list, but when I run the code, I get the following error, I couldn’t figure out why.
Image

`driver.find_element_by_xpath("//img[@id='ctl00_ContentPlaceHolder1_ASPxPageControl1_cbGalopIstatistikMesafe_B-1Img']").click()
sleep(4)
TABLO=[]
for i in range(0,6):
    driver.find_element_by_xpath("//td[@id='ctl00_ContentPlaceHolder1_ASPxPageControl1_cbGalopIstatistikMesafe_DDD_L_LBI{}T0']".format(i)).click()
    sleep(4)
    tablo = driver.find_elements_by_xpath("//tr[contains(@id,'ctl00_ContentPlaceHolder1_ASPxPageControl1_grdGalopIstatistik_DXDataRow')]//descendant::td")
    for i in tablo:
        TABLO.append(i.text)
tablo_duzenleme=[TABLO[x:x+10] for x in range(0, len(TABLO), 10)]
print(tablo_duzenleme)`
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <td class="dxeListBoxItem_Material" id="ctl00_ContentPlaceHolder1_ASPxPageControl1_cbGalopIstatistikMesafe_DDD_L_LBI0T0">...</td> is not clickable at point (358, 220). Other element would receive the click: <div class="dxh-content">...</div>
Asked By: Recep ÇEM

||

Answers:

The error message you’re seeing suggests that there is another element on the page that is overlapping with the element you’re trying to click on, and that the overlapping element is receiving the click instead. This can happen when there are other elements, such as dropdowns or pop-ups, that appear on the page when you hover over or click on certain elements.

One way to work around this issue is to use the ActionChains class in Selenium to perform a click action on the element using JavaScript instead of the regular click() method. Here’s an example of how you can modify your code to use ActionChains:

from selenium.webdriver.common.action_chains import ActionChains

# click on the main tab
tab = driver.find_element_by_xpath("//img[@id='ctl00_ContentPlaceHolder1_ASPxPageControl1_cbGalopIstatistikMesafe_B-1Img']")
ActionChains(driver).move_to_element(tab).click().perform()
sleep(4)

# click on each sub-tab
TABLO = []
for i in range(0, 6):
    sub_tab = driver.find_element_by_xpath("//td[@id='ctl00_ContentPlaceHolder1_ASPxPageControl1_cbGalopIstatistikMesafe_DDD_L_LBI{}T0']".format(i))
    ActionChains(driver).move_to_element(sub_tab).click().perform()
    sleep(4)
    tablo = driver.find_elements_by_xpath("//tr[contains(@id,'ctl00_ContentPlaceHolder1_ASPxPageControl1_grdGalopIstatistik_DXDataRow')]//descendant::td")
    for i in tablo:
        TABLO.append(i.text)

tablo_duzenleme = [TABLO[x:x+10] for x in range(0, len(TABLO), 10)]
print(tablo_duzenleme)

In this example, we use ActionChains to move to the element before clicking on it, which can help to avoid the issue of overlapping elements. Note that this approach may not work in all cases, and there may be other factors causing the ElementClickInterceptedException.

Answered By: YaBek

when looping in for (0,6) range doesn’t work for zero. It does not give an error, it operates on the currently defined tab("1000"). I couldn’t figure out why
Image

from selenium.webdriver.common.action_chains import ActionChains
from selenium import webdriver
from time import sleep
driver= webdriver.Chrome("C:\Users\Recep_PC\Desktop\driver\chromedriver.exe")
driver.get("https://www.hipodromx.com/galop.aspx?Page=1")
sleep(2)
TABLO=[]
for i in range(0,6):
    tab=driver.find_element_by_xpath("//img[@id='ctl00_ContentPlaceHolder1_ASPxPageControl1_cbGalopIstatistikMesafe_B-1Img']")
    ActionChains(driver).move_to_element(tab).click().perform()
    sleep(2)
    sub_tab=driver.find_element_by_xpath("//td[@id='ctl00_ContentPlaceHolder1_ASPxPageControl1_cbGalopIstatistikMesafe_DDD_L_LBI{}T0']".format(i))
    ActionChains(driver).move_to_element(sub_tab).click().perform()
    sleep(2)
    tablo = driver.find_elements_by_xpath("//tr[contains(@id,'ctl00_ContentPlaceHolder1_ASPxPageControl1_grdGalopIstatistik_DXDataRow')]//descendant::td")
    for i in tablo:
        TABLO.append(i.text)

tablo_duzenleme=[TABLO[x:x+10] for x in range(0, len(TABLO), 10)]
print(tablo_duzenleme)
Answered By: Recep ÇEM