Python selenium get inside a #document

2019-05-11 07:14发布

问题:

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>

回答1:

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")