Why is the element not interactable using selenium? selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

Question:

I am trying to login to this [website][1] using selenium and trying to scrape all the data available. However I am facing issues while logging in to the account.
The error reads as:

selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

By looking at the stacktrace, I came to know that there’s a problem while sending the login email..here is the complete stacktrace.

browser.find_element_by_id('username').send_keys('[email protected]')
  File "F:technophilevenvlibsite-packagesseleniumwebdriverremotewebelement.py", line 477, in send_keys
    self._execute(Command.SEND_KEYS_TO_ELEMENT,
  File "technophilevenvlibsite-packagesseleniumwebdriverremotewebelement.py", line 633, in _execute
    return self._parent.execute(command, params)
  File "F:technophilevenvlibsite-packagesseleniumwebdriverremotewebdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "F:technophilevenvlibsite-packagesseleniumwebdriverremoteerrorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
  (Session info: chrome=92.0.4515.159)

And here is my code for the same:

websites = ['https://www.spacresearch.com/symbol?s=live-deal&sector=&geography=']
    data = []
    for live_deals in websites:
        browser.get(live_deals)
        #time.sleep(1)

        browser.find_element_by_id('username').send_keys('[email protected]')
        browser.find_element_by_id('password').send_keys('abc@123%$')
        browser.find_element_by_xpath('/html/body/div[1]/div[1]/form/button').send_keys(Keys.ENTER)

        time.sleep(2)
        #rest of the code

I’ve faced this error a couple of times and I’ve solved it using webriverWait..however this time, it did not solve the issue so I tried introducing sleep time as well. but that did not work as well. I tried something like this:

        # wait =WebDriverWait(browser, 10)
        # wait.until(EC.visibility_of_element_located((By.ID, 'username')))
        # wait.until(EC.visibility_of_element_located((By.ID, 'password')))

What exactly is the cause of error? Please let me know! Thanks alot for your help in advance.
[1]: https://www.spacresearch.com/symbol?s=live-deal&sector=&geography=

Asked By: technophile_3

||

Answers:

The reason why your code did not work is cause, username, password id’s are not unique.

Code :-

websites = ['https://www.spacresearch.com/symbol?s=live-deal&sector=&geography=']
    data = []
    for live_deals in websites:
        browser.maximize_window()
        browser.implicitly_wait(30)
        browser.get(live_deals)
        #time.sleep(1)
        wait = WebDriverWait(browser, 10)

        wait.until(EC.element_to_be_clickable((By.XPATH, "(//input[@id='username'])[2]"))).send_keys("[email protected]")
        wait.until(EC.element_to_be_clickable((By.XPATH, "(//input[@id='password'])[2]"))).send_keys("abc@123%$")
        wait.until(EC.element_to_be_clickable((By.XPATH, "(//button[text()='Next'])[2]"))).click()

        time.sleep(2)
        #rest of the code

Imports :

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

Instead of * give tag_name
driver.find_element(By.XPATH,"//*[@id=’search-icon-legacy’]").click()
becomes
driver.find_element(By.XPATH,"//button[@id=’search-icon-legacy’]").click()

Answered By: user21131392