java - 如何使用 Java 在 Selenium WebDriver 中的帧之间切换

标签 java selenium-webdriver

我正在使用带有 WebDriver 的 java。我必须在两个帧之间切换。我已经在 selenium IDE 中记录了测试用例,其中我得到的值是 selectFrame relative=top select Frame=middle Frame

但是有一个问题是它无法识别 relative=top 和 middleFrame。如何使用 Java 在 Selenium WebDriver 中解决这个问题?

最佳答案

WebDriver 的 driver.switchTo().frame()方法采用三个可能的参数之一:

  • A number.

    Select a frame by its (zero-based) index. That is, if a page has three frames, the first frame would be at index 0, the second at index 1 and the third at index 2. Once the frame has been selected, all subsequent calls on the WebDriver interface are made to that frame.

  • A name or ID.

    Select a frame by its name or ID. Frames located by matching name attributes are always given precedence over those matched by ID.

  • A previously found WebElement.

    Select a frame using its previously located WebElement.

通过它的 id/name 获取框架或通过 driver.findElement() 定位它你会好起来的。

关于java - 如何使用 Java 在 Selenium WebDriver 中的帧之间切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10879206/

相关文章:

java - 如何使用 JavascriptExecutor 返回具有特定 CSS 属性的 WebElement?

java - 我在尝试获取一些数据时将 SQL 状态设置为 null 并关闭语句

java - 使用 WebdriverManager 在多个测试线程中注册驱动程序时出错

Python:使用selenium清除搜索框中的现有字符串

java - 如何在多个 stepDefPages 中针对多个场景使用相同的 chromedriver,并且无需重新启动驱动程序?

java - 随 secret 码生成 selenium webdriver java

java - 为什么我的 Ant 删除不起作用?

java - 我的 REST 方法应该有一个单独的 Controller 吗?

java - JTree 节点的渲染和字体变化

java - 在 Java 中处理 Content-Type = "application/x-www-form-urlencoded"的 SOAP 请求