Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

selenium.common.exceptions.NoSuchElementException: Message:

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").

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? Thanks in advance!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

There are mutliple issues here:
A. After getting the url, you are not waiting for the elements in the page to load completely and hence the elements are not found
B. The locators you have seem dynamic to me, for eg: input-3, I see it as input-5 (although I am on Chrome browser, but that may not rule out that the locators are dynamic). So, I refactored and hunted for some static locator strategies which I pasted below.
C. zipcodeElm.submit() would not work, as it is not the button element. I have refactored this too.
So, here is the code.

driver.get('https://knowledge.tonal.com/s/order-status')
WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "(//div[@data-aura-class='cOrderSearch']//input)[1]")))
orderElm = driver.find_element(By.XPATH, "(//div[@data-aura-class='cOrderSearch']//input)[1]")
orderElm.send_keys('1000XXX')
zipcodeElm = driver.find_element(By.XPATH, "(//div[@data-aura-class='cOrderSearch']//input)[2]")
zipcodeElm.send_keys('90210')
driver.find_element(By.XPATH, "//*[@data-aura-class='cOrderSearch']//parent::div//button").click()

Output: (exit code 0 implies that the code passed without errors)

Process finished with exit code 0
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading