vietnguyenswin
vietnguyenswin

Reputation: 28

ElementNotInteractableException: Message: element not element not interactable error sending text to Email field using Selenium and Python

I have tried all the posts with the same question from others but none of them worked for my case. I need to write a script to get wholesale prices for the website below:

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

LoginURL = "https://www.coffeeparts.com.au/customer/account/login/"

driver = webdriver.Chrome("C:/chromedriver.exe")
driver.delete_all_cookies()

driver.get(LoginURL)

email = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, 'email')))
email.send_keys("test")

driver.close()

For any versions of the code I tried, I always get the same error. I need to run the send_keys method to both email and password fields, then click the login button. After then, I will get the login session information to run web scraper scripts for getting wholesale prices of the items.

---------------------------------------------------------------------------
ElementNotInteractableException           Traceback (most recent call last)
<ipython-input-14-ee71e5f9bc26> in <module>()
     13 
     14 email = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, 'email')))
---> 15 email.send_keys("test")
     16 
     17 driver.close()

c:\python27\lib\site-packages\selenium\webdriver\remote\webelement.pyc in send_keys(self, *value)
    477         self._execute(Command.SEND_KEYS_TO_ELEMENT,
    478                       {'text': "".join(keys_to_typing(value)),
--> 479                        'value': keys_to_typing(value)})
    480 
    481     # RenderedWebElement Items

c:\python27\lib\site-packages\selenium\webdriver\remote\webelement.pyc in _execute(self, command, params)
    631             params = {}
    632         params['id'] = self._id
--> 633         return self._parent.execute(command, params)
    634 
    635     def find_element(self, by=By.ID, value=None):

c:\python27\lib\site-packages\selenium\webdriver\remote\webdriver.pyc in execute(self, driver_command, params)
    319         response = self.command_executor.execute(driver_command, params)
    320         if response:
--> 321             self.error_handler.check_response(response)
    322             response['value'] = self._unwrap_value(
    323                 response.get('value', None))

c:\python27\lib\site-packages\selenium\webdriver\remote\errorhandler.pyc in check_response(self, response)
    240                 alert_text = value['alert'].get('text')
    241             raise exception_class(message, screen, stacktrace, alert_text)
--> 242         raise exception_class(message, screen, stacktrace)
    243 
    244     def _value_or_default(self, obj, key, default):

ElementNotInteractableException: Message: element not interactable

Please help. Thank you very much.

Upvotes: 1

Views: 375

Answers (2)

undetected Selenium
undetected Selenium

Reputation: 193108

You were close. But the locators you were using were identifying the Email Address field of the wholesale-login-form, instead you need to identify the Email Address field of login-form


Solution

To send a character sequence to the Email Address field you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR

    driver.get("https://www.coffeeparts.com.au/customer/account/login/")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "form#login-form ul.form-list input#email"))).send_keys("vietnguyenswin")
    
  • Using XPATH:

    driver.get("https://www.coffeeparts.com.au/customer/account/login/")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//h2[text()='Registered Customers']//following::ul[1]//input[@id='email']"))).send_keys("vietnguyenswin")
    
  • 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
    
  • Browser Snapshot:

coffeeparts


References

You can find a couple of relevant discussions in:

Upvotes: 1

vietnguyenswin
vietnguyenswin

Reputation: 28

Thank you everyone, I still would love to know how you can do that with Selenium. I solved the problem for getting the wholesale price by using different method:

s = requests.Session()

Then I pass the cookies to the get method:

req = s.get(URL, cookies=cookies, headers=headers)

Upvotes: 0

Related Questions