sprogissd
sprogissd

Reputation: 3075

Python Selenium: Element Is Not Clickable At Point

I am using the code below to click on the highlighted tab that you see on the attached screenshot with the corresponding HTML code. The tab is always visible on the bottom of the script so there is no need to scroll down to it.

element = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.ID, "tab-button-settings")))
element.click()

The error that I get is below. What am I doing wrong?

Message: unknown error: Element <a class="tab-button has-icon icon-only" href="#" role="tab" ng- 
reflect-tab="[object Object]" id="tab-button-settings" aria-controls="tabpanel-t0-1" aria- 
selected="false">...</a> is not clickable at point (1440, 1017). Other element would receive the 
click: <div class="click-block click-block-enabled click-block-active"></div>
(Session info: chrome=78.0.3904.108)

enter image description here

Upvotes: 1

Views: 6258

Answers (3)

undetected Selenium
undetected Selenium

Reputation: 193058

The desired element is an Angular element so to locate and click() on the element you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.tab-button.has-icon.icon-only#tab-button-settings"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='tab-button has-icon icon-only' and @id='tab-button-settings']"))).click()
    
  • Note : You have to add the following imports :

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

In case the unknown error still occurs you may have to induce WebDriverWait additionally for the invisibility_of_element_located() and you can use either of the following solutions:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.invisibility_of_element_located((By.CSS_SELECTOR, "div.click-block.click-block-enabled.click-block-active")))
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.tab-button.has-icon.icon-only#tab-button-settings"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.invisibility_of_element_located((By.XPATH, "//div[@class='click-block click-block-enabled click-block-active']")))
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='tab-button has-icon icon-only' and @id='tab-button-settings']"))).click()
    

References

You can find a couple of relevant discussions in:

Upvotes: 0

SeleniumUser
SeleniumUser

Reputation: 4177

you can use action class to avoid above issue

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

from selenium.webdriver.common.action_chains import ActionChains

element = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.ID, "tab-button-settings"))
ActionChains(driver).move_to_element(element).click().perform()

Upvotes: 3

john
john

Reputation: 443

Another way alternative to javascript is to use touch actions

from selenium.webdriver.common.touch_actions import TouchActions

element = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.ID, "tab-button-settings")))

touchactions = TouchActions(driver)
touchactions.tap(element).perform()

Upvotes: 0

Related Questions