Skip to content Skip to sidebar Skip to footer

Selenium WebDriver Unable To Find Element By Id, Using Python

I'm trying to pull up an element that only gets created after the JavaScript runs, but I keep getting the following error message: selenium.common.exceptions.NoSuchElementException

Solution 1:

The element you are looking for is inside an iframe.

The following did the trick for me:

from selenium.webdriver.support.wait import WebDriverWait

# ...

frame = WebDriverWait(browser, 30).until(lambda x: x.find_element_by_id("dsq1"))
browser.switch_to_frame(frame)
result = WebDriverWait(browser, 30).until( lambda x: x.find_element_by_id("post-count"))

Note that I included the use of WebDriverWait(...).until(...) to allow the elements to be created dynamically just in case.


Solution 2:

You can tell the WebDriver to wait implicitly until the element is visible.

browser.implicitly_wait(30)
result = browser.find_element_by_id("post-count")

Post a Comment for "Selenium WebDriver Unable To Find Element By Id, Using Python"