The difference between 1.frame and IFRAME:
Frame is the framework of the entire page, and the IFRAME is the embedded frame
The IFRAME tag is also called a floating frame marker, which you can use to embed an HTML document in an HTML display. The biggest difference between it and the Frame tag is that the embedded <Iframe></Iframe> in the Web page is a whole page, and the <Frame></frame> contains a single individual , it can be displayed independently. In addition, the application of an IFRAME can also display the same content multiple times on the same page without having to repeat the code for this section of content.
2. Use id,name positioning
#coding =utf-8 from
Selenium import webdriver
driver = webdriver. Firefox ()
driver.get (' http://mail.163.com ')
driver.switch_to.frame (' x-urs-iframe ')
driver.find_ element_by_id (' auto-id-1513149691275 '). Send_keys (' 18707718538 ')
driver.find_element_by_id (' auto-id-1513149691276 '). Send_keys (' 111111 ')
Note: Selenium automatically claims that the Switch_to_frame is underlined and can be changed to Switch_to.frame
3. If the IFRAME does not have ID or name how to locate.
There are eight ways of this element, we can use XPath or tag to locate
4. Release the IFRAME
When the operation is completed on the IFRAME, want to return to the home page to continue operation, you must first release the IFRAME in operation
#coding =utf-8 from
Selenium import webdriver
driver = webdriver. Firefox ()
driver.get (' http://mail.163.com ')
driver.switch_to.frame (' x-urs-iframe ')
driver.find_ element_by_id (' auto-id-1513149691275 '). Send_keys (' 18707718538 ')
driver.find_element_by_id (' auto-id-1513149691276 '). Send_keys (' 111111 ')
#释放iframe
driver.switch_to_default.content ()
5. How to determine if the elements on the page are in the IFRAME frame
1. After positioning to the element, switch to the Firepath interface
2. Look at the upper left corner of the Firebug tool, if Show top window shows no IFRAME
3. If the display iframe#xxx such, description on the IFRAME, #后面就是它的id
4. You can also view the source code to see if the target element is in the IFRAME frame