Selenium 2 + python iframe locator

Source: Internet
Author: User

When you position a page element, you sometimes encounter an IFRAME. If the IFRAME has an ID or name, using Switch_to_frame () can be conveniently located. But sometimes there is no ID in the IFRAME or the situation, which requires other means to locate.

Page structure:

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/76/85/wKiom1ZVYxTj6IZ-AAH4n9MDuCk426.jpg "title=" IFRAME page structure. jpg "alt=" wkiom1zvyxtj6iz-aah4n9mduck426.jpg "/> Method One: Starting from the top level, relatively laborious.

Text1 = Browser.find_element_by_class_name ("BODYBG")
Text2 = Text1.find_element_by_xpath ("div[@class = ' lean_overlay ']/div[2]")
Text3 = Text2.find_element_by_tag_name ("iframe"). Get_attribute ("src")
Print text3# input the src content in the IFRAME, confirming that the IFRAME has been located
Text = Text2.find_element_by_tag_name ("iframe")
Browser.switch_to.frame (text)

Method Two: Locate the last time, and then locate the IFRAME.

#找出所有class_name the upper element of the =qh-login
Text1 = Browser.find_elements_by_class_name ("Qh-login")
For text in Text1:
If Text.get_attribute ("id") = = = "Idname":
Print Text.get_attribute ("class")
Text2 = Text.find_element_by_tag_name ("iframe"). Get_attribute ("src")
Else
Text2 = str ("Location failed")


Selenium 2 + python iframe locator

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.