Reputation: 3
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.
Upvotes: 0
Views: 238
Reputation: 2461
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:
Upvotes: 1