Python+selenium Primary (6)-by switching the IFRAME positioning element

Source: Internet
Author: User

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



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.