NaiboWang/EasySpider · error · NoSuchElementException

Elements with {value} not found in any frame or iframe

Error message

Elements with {value} not found in any frame or iframe

What it means

Raised by MyChrome.find_elements_recursive (ExecuteStage/myChrome.py:164) as NoSuchElementException after all frames and nested iframes have been searched without finding ANY matching element (plural variant). Counterpart of error 4 for the find_elements path.

Source

Thrown at ExecuteStage/myChrome.py:164

                    self.switch_to.frame(frame)
                except StaleElementReferenceException:
                    # If the frame has been refreshed, we need to switch to the parent frame first,
                    self.switch_to.parent_frame()
                    self.switch_to.frame(frame)
                # Directly find elements in the current frame
                elements = super(MyChrome, self).find_elements(by=by, value=value)
                if elements:
                    return elements
                # Recursively search for elements in nested iframes
                nested_frames = super(MyChrome, self).find_elements(By.CSS_SELECTOR, "iframe")
                if nested_frames:
                    elements = self.find_elements_recursive(by, value, nested_frames)
                    if elements:
                        return elements
            except Exception as e:
                print(f"Exception while processing frame: {e}")

        raise NoSuchElementException(f"Elements with {value} not found in any frame or iframe")

    def find_elements(self, by=By.ID, value=None, iframe=False):
        self.switch_to.default_content()  # Switch back to the main document
        self.iframe_env = False
        if iframe:
            frames = self.find_elements(By.CSS_SELECTOR, "iframe")
            if not frames:
                return []  # Return an empty list if no iframes are found
            self.iframe_env = True
            elements = self.find_elements_recursive(by, value, frames)
        else:
            # Find elements in the main document as normal
            elements =  super(MyChrome, self).find_elements(by=by, value=value)
        return elements


class MyEdge(webdriver.Ie):
    def __init__(self, *args, **kwargs):

View on GitHub (pinned to 191bd6d754)

Solutions

  1. Validate the XPath returns nodes in the browser DevTools (within the correct iframe context).
  2. Wait for the iframe and a representative child element before collecting.
  3. If the iframe is cross-origin or shadow-bound, switch to a JS executeScript extraction strategy.
  4. Confirm at least one iframe exists (the caller find_elements returns [] rather than throwing when there are none, so a throw here means iframes exist but hold no matches).

Example fix

# before
items = driver.find_elements(By.XPATH, xpath, iframe=True)

# after - wait then collect
WebDriverWait(driver, 10).until(
    EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, 'iframe')))
items = WebDriverWait(driver, 10).until(
    lambda d: d.find_elements(By.XPATH, xpath))
driver.switch_to.default_content()
Defensive patterns

Strategy: try-catch

Validate before calling

frames = driver.find_elements(By.CSS_SELECTOR, 'iframe')
if not frames:
    result = []  # caller returns [] in this case, but guard anyway

Try / catch

from selenium.common.exceptions import NoSuchElementException
try:
    items = driver.find_elements(By.XPATH, xpath, iframe=True)
except NoSuchElementException as e:
    if 'not found in any frame or iframe' in str(e):
        items = []
    else:
        raise

Prevention

When it happens

Trigger: driver.find_elements(by, value, iframe=True) -> find_elements_recursive(by, value, frames). For each frame: switch, super().find_elements(...); if non-empty return, else recurse into nested iframes. Loop exhaustion raises NoSuchElementException(f'Elements with {value} not found in any frame or iframe').

Common situations: Bulk data-extraction loops target elements inside iframes that have not loaded; recorded collection XPath is stale; cross-origin iframe blocks access; shadow DOM hides the nodes.

Related errors


AI-assisted analysis of NaiboWang/EasySpider@191bd6d754 (2026-08-13). Data as JSON: /api/errors/63316040fb86131f. Report an issue: GitHub.