Error "Other element would receive the click" in Python

mikezang picture mikezang · Sep 19, 2018 · Viewed 8.2k times · Source

I tried to click a link like this:

<div class="loading" style="display:none;">
<p class="btn blue"><span>さらに表示</span></p>
<a href="javascript:void(0);" onclick="get_more();"></a>
</div>

and I used this code:

element = WebDriverWait(driver, 30).until(lambda x: x.find_element_by_css_selector(".btn.blue"))  # @UnusedVariable
element.click()

I got an error like this, what can I do to solve it?

selenium.common.exceptions.WebDriverException: Message: unknown error: Element <p class="btn blue">...</p> is not clickable at point (391, 577). Other element would receive the click: <a href="javascript:void(0);" onclick="get_more();"></a>
(Session info: headless chrome=69.0.3497.100)
(Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 6.1.7601 SP1 x86_64)

Answer

NarendraR picture NarendraR · Sep 19, 2018

Element on which you are trying to click has been covered by some other element so that other element getting the click instead of the actual element.

There may be following possibilities that actual element not getting clicked:

  • Case 1. lets say if its a loader which comes while your element getting load and get invisible after some time.

    Solution: Here you have to wait until the loader get invisible and then have to perform click on actual element

      from selenium.webdriver.support import expected_conditions as EC
      wait = WebDriverWait(driver, 10)
      element = wait.until(EC.invisibility_of_element_located((By.ID, 'loader_element_id')))
      element_button = wait.until(EC.element_to_be_clickable((By.ID, 'your_button_id')))
      element_button.click()
    
  • Case 2. actual element is not visible within browser dimension and covered by some overlay element.

    Solution: Here you need to scroll to the required element and then have to perform the click

      from selenium.webdriver.common.action_chains import ActionChains
    
      element = driver.find_element_by_id("your_element_id")
    
      actions = ActionChains(driver)
      actions.move_to_element(element).perform()
    

    OR use can use execute_script like :

      driver.execute_script("arguments[0].scrollIntoView();", element)
    

    OR perform the click using JavaScript.

      driver.execute_script("arguments[0].click();", element) 
    

Note: Please make necessary correction as per Python syntax if require.