Objective
There are a lot of small partners in the 163 as a login case, found that no matter how positioning can not locate, what is the ghost, this article details the IFRAME related switch
Take http://mail.163.com/login page for the case, detailed introduction Switch_to_frame use method.
First, frame and iframe differences
The functions of frame and IFRAME are basically the same, but IFrame has more flexibility than frame. Frame is the framework of the entire page, the IFRAME is an inline page element, or it can be said to be an inline frame
An IFRAME tag is also called a floating frame marker, which can be used to embed an HTML document in an HTML display. The biggest difference between it and the Frame tag is that the embedded <Iframe></Iframe> content in the Web page is a whole, and <Frame></Frame> contains content that is a separate entity. , it can be displayed independently. In addition, the application IFRAME can display the same content multiple times on the same page without having to repeat the code for that piece of content.
Two, 163 login interface
1. Open the http://mail.163.com/login page
2. Locate the login box with Firebug
3. When the mouse hovers in the lower-left corner (anchored to the IFRAME location), the entire login box in the upper-right corner is grayed out, indicating that the IFRAME area is the entire login box area
4. The lower left arrow position displays the IFrame property <iframe id= "X-urs-iframe" frameborder= "0" name= ""
Third, switch IFRAME
1. Since the login button is on the IFRAME, the first step is to switch the locator to the IFRAME
2. Use the Switch_to_frame method to switch, there is an id attribute, you can directly use the ID to locate the switch
Iv. What if the IFRAME does not have an ID?
1. Here the IFRAME switch is the default support ID and name method, of course, the actual situation will encounter no id attribute and the Name property is empty, it is necessary to locate the IFRAME first
2. Positioning elements or the previous eight methods also apply, here I can go through the tag to locate, but also to achieve the same effect
QQ Exchange Group: 232607095
(All rights reserved: "Software Test Tribe" public number)
V. Release of the IFRAME
1. After the operation on the IFRAME, want to return to the main page to manipulate the elements, this time, you can use the Switch_to_default_content () method to return to the main page
Six, how to determine whether the element is on the IFRAME?
1. After locating the element, switch to the Firepath interface
2. Look at the upper left corner of the Firebug tool, if the top window shows no IFRAME
3. If iframe#xxx is displayed, the description is on the IFRAME, #后面就是它的id
?
Seven, how to solve the switch_to_frame on the horizontal line?
1. First find the Official document introduction
1475043314131380.png973x301 7.57 KB
2. The official has not recommended the above wording, the use of this notation is good driver.switch_to.frame ()
Eight, the reference code is as follows
# Coding:utf-8
From selenium import Webdriver
Driver = Webdriver. Firefox ()
Driver.get ("http://mail.163.com/")
Driver.implicitly_wait (30)
# Toggle IFrame
# iframe = Driver.find_element_by_tag_name ("iframe")
# driver.switch_to_frame (IFRAME)
# driver.switch_to_frame ("X-urs-iframe")
Driver.switch_to.frame ("X-urs-iframe")
Driver.find_element_by_name ("email"). Send_keys ("123")
Driver.find_element_by_name ("password"). Send_keys ("456")
# Release the IFrame and go back to the main page
Driver.switch_to.default_content ()
Selenium2+python Automation 14-iframe