Unable to click with Selenium in nested frames

天涯浪子 提交于 2019-12-12 01:38:16

问题


I am trying to navigate on a page with nested frames. The page structure looks like this:

<frameset name="framesetContainer">
  <frame name="WebTopMenu">
  ...
  </frame>
  <frame name="WebContent">
    <frameset name="framesetTopContainer">
      <frameset name="framesetWSTopMenu">
        <frame name="frameTitle">
        ...
        </frame>
        <frame name="frameTopMenu">
        ...
        </frame>
      </frameset>
      <frameset name="framesetLeftMenuContentContainer">
        <frameset name="framesetLeftMenuContainer">
        ...
        </frameset>
        <frame name="frameContent">
        ...
        </frame>
      </frameset>
    </frameset>
  </frame>
</frameset>

The links to navigate reside in the frameTopMenu frame and the content is loaded into frameContent.

I am using the WebDriver API of Selenium (2.35.0). The following code runs fine without any exception, it finds the correct link but somehow the click() call does not have any effect and the content is not loaded into the inner frame.

driver.switchTo().frame("WebContent").switchTo().frame("frameTopMenu");
driver.findElement(By.id("link01")).click();

Do I miss something?

The frame structure cannot be changed...unfortunately.


回答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:


Try below solution for nested frames.Hope it works

driver.switchTo().frame("WebContent").switchTo().
  frame("framesetTopContainer").switchTo().
  frame("framesetWSTopMenu").switchTo().
  frame("frameTitle");


来源:https://stackoverflow.com/questions/18875235/unable-to-click-with-selenium-in-nested-frames

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