Selenium2 + python automated 14-iframe

Reprinted: https://www.cnblogs.com/yoyoketang/p/6128619.html

Foreword   

There are many small partners take 163 as a login case, I found no matter how positioning can not be located, in the end what the hell it is herein, this detailed description of the relevant switching iframe 

To http://mail.163.com/ login page 10 for the case, detailing switch_to_frame use.

 

A, frame and iframe difference

    Both Frame and Iframe can realize the function is basically the same, but with more flexibility than Iframe Frame. the entire page frame is a frame, iframe is embedded page elements, it can be said that the embedded framework

    Iframe tag called floating frame markers may be embedded with it in an HTML document displayed in an HTML. It biggest difference Frame markers are embedded in a web page <Iframe> </ Iframe> included in the content of the entire page as a whole, and the content <Frame> </ Frame> included is a separate entity, is It can be independently displayed. In addition, the application Iframe can also display the same content multiple times on the same page, without having to duplicate code this content.



Second, the login screen 163

    1. Open http://mail.163.com/ login page 10

    2. firebug positioning login box

    3. When the mouse is in the lower left (iframe target position), the upper right corner show the entire login gray box, the entire region described iframe login box region

    4. The lower left corner of the display position of the arrow iframe attributes <iframe id = "x-URS-iframe" frameborder = "0" name = "" 

 Third, switching iframe

    1. Since a login button on the iframe, so the first step is switched to the need to position the iframe

    2. switch_to_frame method switching, where id attribute can be used to switch directly positioned id

Fourth, if no iframe id how to do?

    1. iframe switch here is supported by default id and name of the method, of course, will encounter no id and name attributes are empty of actual cases, this time on the need to locate iframe

    2. positioning element or before eight methods are equally applicable, where I can locate the first tag, can achieve the same effect

QQ exchange group: 232 607 095

(Copyright: "yoyoketang" micro-channel public number)

    1. When the operation after the iframe, like operating element back on the main page, this time, it is possible () method returns to the main page with switch_to_default_content

6, how to determine whether the elements in the iframe?

    1. Locate the element, the interface switch to firepath

    2. Look at the upper left corner firebug tool, if no iframe display Top Window Description

    3. If this iframe # xxx is displayed, indicating that the iframe, its id is the back #


Seven, how to solve the horizontal line on the switch_to_frame it?    

    1. First find the document describes the official release of

    2. officials have not recommended wording of the above, with this wording like driver.switch_to.frame ()

Eight, the following reference code

# coding:utf-8

from selenium import webdriver

 

driver = webdriver.Firefox()

driver.get("http://mail.163.com/")

driver.implicitly_wait(30)

# Switch 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 iframe, back to the main page

driver.switch_to.default_content()

In the learning process there in case of doubt, you can add selenium (python + java) QQ exchange group: 646 645 429

"Selenium + python advanced tutorial" has a book: the Selenium  webdriver source Python-based Case

Guess you like

Origin www.cnblogs.com/yuany66/p/11344988.html