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