0

Receiving the error: "selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element:"

browser.find_element(By.XPATH, "//input[@id='email']")
browser.find_element_by_id("email")
browser.find_element_by_id("input")
browser.find_element_by_class("inputtext")
browser.find_element_by_class_name("_55r1")
browser.find_element_by_class_name("login")
browser.find_element_by_class_name("login_page")
browser.find_element_by_class_name('login_form_label')
browser.find_element_by_class_name('label.login_form_label')
browser.find_element(By.XPATH, "//label[text()='Email or Phone']")
browser.find_element_by_id("email_container")

Even added an browser .implicity_wait(10)

All yielding the same error.

Any ideas?

Source code

  • The correct solution was a handler issue with a new window: https://stackoverflow.com/questions/10629815/how-to-switch-to-new-window-in-selenium-for-python –  Jul 18 '19 at 20:00

1 Answers1

0
  1. Make sure that the element you're looking for doesn't belong to an iframe, otherwise you will have to use switch_to_frame function in order to change the context to the relevant iframe prior to locating the element
  2. Make sure that the element you're looking for isn't hidden in the Shadow DOM, otherwise you will have to locate the relevant ShadowRoot and cast it to the WebElement, once done use WebElement.find_element_by function to locate the element (not browser.find_element_by)
  3. In any case I would recommend using Explicit Wait as it might be the case the element is not immediately available in DOM (for example it's being loaded via an AJAX call)

    email = WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.ID, "email")))
    
Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • I accepted to close the topic, or should there be another course of action for this thread? –  Jul 18 '19 at 20:00