selenium positioning frame objects

Then the web application will often have A, B frame on two frame nested applications, assuming a page, wherein B in A, B, then the target content is required first to A, then B.

switch_to_frame method can locate the current topic switched to the frame, in the frame is actually nested inside another page, and you can only webdriver in a page recognition, so switch_to_frame way to get frame nested page.

driver.switch_to.frame('frame 1')  #移动到id为frame 1的frame上
print driver.find_element_by_css_selector("#div1").text
   
driver.switch_to.default_content()  #将识别的主体切换出frame
print driver.find_element_by_css_selector("#id1").text

Note: The
parameters must be switch_to.frame id or name, so long as there is a frame id and name are easy to deal with. If not, the idea of two solutions:
1, allows developers to add id or name
2, then use xpath other ways to achieve localization Jump

Guess you like

Origin www.cnblogs.com/TD1900/p/11975719.html