无法在嵌套框架中使用硒单击 [英] Unable to click with Selenium in nested frames

查看:203
本文介绍了无法在嵌套框架中使用硒单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试浏览带有嵌套框架的页面.页面结构如下:

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>

要导航的链接位于 frameTopMenu 框架中,并将内容加载到 frameContent 中.

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

我正在使用Selenium(2.35.0)的WebDriver API.以下代码可以正常运行,可以找到正确的链接,但是以某种方式c​​lick()调用不会产生任何效果,并且内容也不会加载到内部框架中.

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();

我想念什么吗?

不幸的是,无法更改框架结构.

推荐答案

切换到任何框架元素,只需使用driver.switchTo().frame("framename");

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();

driver.switchTo().parentFrame();

如果使用driver.switchTo().defaultContent();,则可能不起作用.因此,选择driver.switchTo().parentFrame();即可.

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

这篇关于无法在嵌套框架中使用硒单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆