0

I am using Selenium to click a button but I am getting a ElementNotInteractableException.

Here is the Selenium Python snipit:

b.driver.find_element(By.CLASS_NAME,"button-prm-light").click()

Here is the html:

<button class="button-prm-light button-height-40 button-padding-fill button-rounded"         
    ng-hide="vm.isBlockedOrBlockedByMe() || vm.isPrivateAndHidden() || vm.isOwnProfile" 
    talk-to="8d056f47-c680-e711-80c2-0003ff4668ed" talk-to-type="user"> <i class="icon- 
    speech-bubbles"></i> <span>Chat</span> </button>

Any ideas on how to do this?

Shawn
  • 4,064
  • 2
  • 11
  • 23
Justin
  • 297
  • 1
  • 2
  • 10
  • There are several similar questions for this. You can try to search stackoverflow for existing solutions (e.g. https://stackoverflow.com/questions/43868009/how-to-resolve-elementnotinteractableexception-element-is-not-visible-in-seleni). Mostly would include either using JavaScriptExecutor, Scrolling or moving into the element. – lorvindc Aug 30 '23 at 11:06

2 Answers2

2

Try one of the following:

  1. By applying ExplicitWaits:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CLASS_NAME,"button-prm-light"))).click()
  1. Using Javascript:
button = b.driver.find_element(By.CLASS_NAME,"button-prm-light")
driver.execute_script("arguments[0].click();", button)
  1. Using Action Chains:
button = b.driver.find_element(By.CLASS_NAME,"button-prm-light")
ActionChains(driver).move_to_element(button).click().perform()

Imports required:

from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Shawn
  • 4,064
  • 2
  • 11
  • 23
1

ElementNotInteractableException is happened, when your element is exist in DOM, but can't be interacted by user actions directly. Possible reasons:

  1. Another element overlaps your element.
  2. It's hidden
  3. It doesn't have actual location and bounding box props (width, height, x, y is 0)

As one of the easiest workarounds is to execute JS code that clicks on the element. (if it's overlapped by some modal, tooltip or backdrop, I suggest to close the modal and not to use this solution)

button_primary = b.driver.find_element(By.CLASS_NAME,"button-prm-light")
driver.execute_script('arguments[0].click()', button_primary)

If element is overlapped, sometimes using ActionChains can help. For example, in case when you have merged footer and button is placed below it.

button_primary = b.driver.find_element(By.CLASS_NAME,"button-prm-light")
element_location = button_primary.location
actionChains.move_by_offset(element_location['x'] + 1, element_location['y'] + 1).click().perform()
Yaroslavm
  • 1,762
  • 2
  • 7
  • 15