pythonseleniumiframescraper

Python selenium get inside a #document


How can I keep looking for elements in a #document:

<div>
    <iframe>
        #document
            <html>
               <body>
                   <div>
                        Element I want to find  
                   </div>
               </body>
            </html>
    </iframe>
</div>

Solution

  • I think your problem is not with the a#document but with iframe.

    from selenium import webdriver
    
    driver = webdriver.Firefox()
    iframe = driver.find_elements_by_tag_name('iframe')[0]
    driver.switch_to.frame(iframe)
    
    driver.find_element_by_xpath("//div")