Search code examples
python-3.xseleniumselenium-chromedriversendkeystraceback

Python Selenium: Send_keys Failed to execute


I'd like to fill out a form with

driver.find_element_by_id("name").send_keys("Test")

But I get this error everytime I run the script:

Traceback (most recent call last):
  File "fill.py", line 22, in <module>
    driver.find_element_by_id("name").send_keys("Test")
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 351, in find_element_by_id
    return self.find_element(by=By.ID, value=id_)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 955, in find_element
    'value': value})['value']
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
    self.error_handler.check_response(response)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to execute 'contains' on 'Node': parameter 1 is not of type 'Node'.
  (Session info: chrome=66.0.3359.117)
  (Driver info: chromedriver=2.38.552518 (183d19265345f54ce39cbb94cf81ba5f15905011),platform=Mac OS X 10.13.4 x86_64)

<input first_and_last="true" placeholder="name" class="string required" type="text" name="flname" id="name">

Note: I also get an error for searching for the name. If I search for Xpath it fills out the form very slow and I need it to be faster.

How can I solve this problem?


Solution

  • Use either of the locator Strategies :

    • css_selector :

      driver.find_element_by_css_selector("input.string.required#name").send_keys("Test")
      
    • xpath :

      driver.find_element_by_xpath("//input[@class='string required' and @id='name']").send_keys("Test")
      

    Update

    I have tried to lookout for a solution to both of the error messages you were facing and here are the relevant details :