Selenium ---- iframe tag switching

Switch_to.frame ()
   when we are doing UI test automation, some pages will be nested iframe tag, then you need to use switch_to module selenium available separately

Use
method: If iframe id attribute or attributes have a name, may be written directly in the frame, as shown in FIG HTML code:

May be directly driver.switch_to.frame ( 'top-frame')

Method 2: If no iframe id attributes or attribute name, the iframe Element can accept positioning, so that positioning can be performed by any one of the targeting method, as described above may also be source
1. The first targeting property with iframe
frameElement = Driver. find_element_by_css_selector ( '[the src = "/ new new-index /"]')
2. in the element to be switched by the positioning
driver.switch_to.frame (frameElement)

Method three: when there multilayer iframe nested layers of switches need to find, or can not find
driver.switch_to.frame ( 'Top-Frame')      ---- switched to the first layer
driver.switch_to.frame ( 'baidu-Frame')  ----
switch to the second layer

Method four: switching from the inside layer out iframe
driver.switch_to.parent_frame ()      ---- return to the previous frame
driver.switch_to.default_content ()  ---- Returns the outermost frame

Guess you like

Origin www.cnblogs.com/yttbk/p/11027983.html