Python selenium get inside a #document
Asked Answered
L

1

7

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>
Leinster answered 14/7, 2016 at 0:15 Comment(1)
Do u mean you have to search for this element "Element I want to find " in the document?Bainmarie
R
18

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")
Radiosensitive answered 14/7, 2016 at 0:21 Comment(3)
tanks, that worked! And after that if I want to get the text of a span without id, class, or name? What can I do?Leinster
element = driver.find_element_by_xpath("//span"), element.get_attribute("innderHTML")Radiosensitive
the actual xpath may not be as simple as "//span", it depends on your actual HTML document layout.Radiosensitive

© 2022 - 2024 — McMap. All rights reserved.