Search code examples
pythonhtmlseleniumxpathwebdriverwait

selenium.common.exceptions.NoSuchElementException error sending text to input fields using Selenium and Python


I'm trying to write a simple program to fill out a form (including order ID and zip code) to be submitted but I keep getting the following error:

selenium.common.exceptions.NoSuchElementException: Message: "  (without any text following "Message

Code trials:

from selenium import webdriver
browser = webdriver.Safari()
browser.get('https://knowledge.tonal.com/s/order-status')

orderElm = browser.find_element_by_id('input-3')
orderElm.send_keys('1000XXX')

zipcodeElm = browser.find_element_by_id('input-4')
zipcodeElm.send_keys('90210')
zipcodeElm.submit()

I've double-checked my element ID several times and though I'm very new to this, I'm fairly confident I have the correct element IDs. What am I doing incorrectly?


Solution

  • To send a character sequence to the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

    • Using XPATH:

      driver.get("https://knowledge.tonal.com/s/order-status")
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@data-aura-class='cOrderSearch']//following::input[1]"))).send_keys('1000XXX')
      driver.find_element(By.XPATH, "//div[@data-aura-class='cOrderSearch']//following::input[2]").send_keys("90210")
      
    • 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:

    tonal_com