How to traverse through different frames inside an iFrame?

谁说胖子不能爱 提交于 2019-12-06 05:37:12

问题


I have a iframe given below, I can traverse to iframe, but can't perform any operations like traverse or click on other components or frames inside the frameset. How do I click the frames/elements inside the frameset?

<iframe id="selector_window" name="selector_window" src="/webadmin/webeditor/selectormanager_wcm.jsp? width="750" height="450">
<html><head>
<meta http-equiv="pragma" content="no-cache">
</head>
<frameset rows="*,100" border="1" bordercolor="Gray">
    <frameset cols="200,200,200" border="1" bordercolor="Gray">
        <frame name="selectorlistfilter" src="blank.html" frameborder="1">
        <frame name="selectorlist" src="blank.html" frameborder="1">
        <frame name="selectorpreview" src="blank.html" frameborder="1">
    </frameset>
    <frame name="selectorinsert" src="blank.html" marginwidth="2" marginheight="2" frameborder="0">
</frameset>
</html>
</iframe>         

回答1:


switch to any frame element , just use driver.switchTo().frame("framename");

Once we switched to one frame, if we need to switch to another frame, we have to switch to the parent frame.For that use

driver.switchTo().parentFrame();

If you use driver.switchTo().defaultContent();, it may not work. so go for driver.switchTo().parentFrame();, it works fine.




回答2:


In selenium always follow the sequence. From parent->child1->child2 and again 
Webdriver parent = driver.switchTo().frame(0);
Webdriver child1 = driver.switchTo().frame(1);
Webdriver child2= driver.switchTo().frame(2);
going back to parent 

driver.switchTo().frame(1)
driver.switchTo().defaultcontent();


来源:https://stackoverflow.com/questions/25869502/how-to-traverse-through-different-frames-inside-an-iframe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!