web automated testing -selenium a multi-form switching

I. Overview

  1, in web applications often encounter application frame / iframe form nested page

  2, WebDriver only identification and location of the elements on a page

  3, for the elements on the page frame / iframe embedded in a form of identification and location can not be

  4, then you need to switch to the frame / iframe form

  5, by switching switch_to.frame () method

  6. Method Description

    switch_to.parent_content () out of the current form, return to the previous form

    switch_to.default_content () jumps to the outermost layer of the page

    By frame_name, index, webelement objects, objects recommended webelement   

1 driver.switch_to.frame('frame_name')
2 driver.switch_to.frame(1) 
3 driver.switch_to.frame(driver.find_element_by_tag_name("iframe"))

Second, code implementation

. 1  from Selenium Import the webdriver
 2  
. 3 DR = webdriver.Chrome ()
 . 4 dr.implicitly_wait (10 )
 . 5 dr.get ( ' HTTP: // XXXXXXXXXXX ' )
 . 6  
. 7  # positioned to the frame element 
. 8 frame dr.find_element_by_xpath = ( ' XXXXX ' )
 . 9 dr.switch_to.frame ( ' WebElement objects ' )
 10  
. 11  # Back outermost page 
12 is  dr.switch_to.default_content ()
 13 is  
14  # returns the frame layer
15 dr.switch_to.parent_frame('webelement对象')
16 
17 dr.quit()

 

Guess you like

Origin www.cnblogs.com/puti306/p/11877469.html