selenium in python : NoSuchElementException: Message: no such element: Unable to locate element

JAE_RYONG picture JAE_RYONG · Nov 23, 2018 · Viewed 10.3k times · Source

I tried typing 'abc' in the first block of id and 'cdef' in the second block of password. However, the error code at the bottom comes up.

from selenium import webdriver
driver.get('http://sugang.korea.ac.kr')

Added implicitly wait to prevent the code from executing before the page fully loads.

driver.implicitly_wait(30)

Code for adding username and password is as below

driver.find_element_by_name('id').send_keys('abc') driver.find_element_by_name('pw').send_keys('cdef')

But getting below error

NoSuchElementException: Message: no such element: Unable to locate element: {"method":"id","selector":"id"}

please. help me ^^

Answer

Kaushik picture Kaushik · Nov 23, 2018

No Such Element Exception usually comes when web driver can't see the element you are trying to perform an action on. Reason's can be:

  1. your ID or Name or Xpath or CssSelector can be wrong.

  2. Your element might be inside an an iframe so that web driver can't see or detect it. Switch to an iframe through Selenium and python

  3. Your element is taking time to appear on the UI, so you can use an explicit wait to solve this. https://selenium-python.readthedocs.io/waits.html