0

I have a website that generates a report within an iframe, and the website's HTML structure is laid out to look like the following:

<html> <!-- a -->
  <body>
    .
    . (C)
    .
    <iframe>
      <html> <!-- b -->
        <body>
        .
        . (D)
        .
        </body>
      </html>
    </iframe>
  </body>
</html>

I am wondering how I can access elements in the body containing "(D)" from above. So far I have tried using xpath, but if I copy the xpath from an element in (D) in begins from html tag b, so when the program starts searching from html tag a, it finds nothing. I tested to see if the has any child web elements, and it has 0. Attempts to search for elements in (D) by ID have also also resulted in NoSuchElementException. Not a time problem because I am using WebDriverWait for 120 seconds to make sure everything on page has loaded. Thank you for any help you can provide.

1 Answer 1

1

Because it's in an iframe you need to use switchTo to grab the DOM of the frame. See more here: https://www.techbeamers.com/switch-between-iframes-selenium-python/ or https://www.guru99.com/handling-iframes-selenium.html

driver.switch_to.iframe(self,frame reference)

where reference is:

  • By using the tag name ( in this case ‘iframe’)
  • By using the Id of IFrame
  • By using the name of IFrame
  • Sign up to request clarification or add additional context in comments.

    Comments

    Your Answer

    By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.