Selenium — Despite the element being visible and present in the DOM, Selenium click does not function.

Nishith Shah
Quality Engineering University
2 min readFeb 13, 2023

If the Selenium click method is not working even though the element is visible, there could be several reasons for this issue. Here are some things you can try to resolve the issue:

Check the element’s HTML attributes: Sometimes, certain HTML attributes like disabled, readonly, or style with display:none can prevent an element from being clicked, even though it is visible on the page.

  1. Wait for the element to be clickable: You can use the WebDriverWait class from the selenium.webdriver.support.ui module to wait for the element to be clickable before clicking it.
  2. Try using JavaScript to click the element: If the element is visible but cannot be clicked using the click method, you can try clicking it using JavaScript. You can use the execute_script method to run the JavaScript code that clicks the element.
    element = driver.find_element_by_xpath(“//button[@id=’element_id’]”)
    driver.execute_script(“arguments[0].click();”, element)
  3. Check the element’s size and location: Sometimes, elements can be covered by other elements on the page, making them unclickable. You can use the size and location properties to check the element's position on the page.
  4. Check if there are multiple elements with the same selector: If there are multiple elements with the same selector on the page, Selenium may be interacting with the wrong one. You can add additional criteria to your selector, such as the element’s text, to ensure that you are interacting with the correct element.

These are some of the common reasons for the Selenium click method not working even though the element is visible. Try these solutions one by one, and hopefully, one of them will resolve your issue.

Let me know — along with any questions, comments, or feedback that you might have on https://www.linkedin.com/in/nshthshah.

--

--