如何使用 Java 在 Selenium WebDriver 中的帧之间切换 [英] How to switch between frames in Selenium WebDriver using Java

查看:24
本文介绍了如何使用 Java 在 Selenium WebDriver 中的帧之间切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 WebDriver 中使用 java.我必须在两个框架之间切换.我已经在 selenium IDE 中记录了测试用例,并且我得到的值为 selectFrame relative=top select Frame=middle Frame

I am using java with WebDriver.I have to switch between two frames. I have recorded the test case in selenium IDE and in that I got the values as selectFrame relative=top select Frame=middle Frame

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

But there is a problem it is not able to recognize the relative=top and middleFrame. How can I solve this problem in Selenium WebDriver with Java?

推荐答案

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

WebDriver's driver.switchTo().frame() method takes one of the three possible arguments:

通过(从零开始的)索引选择一个框架.也就是说,如果一个页面有三个帧,第一帧位于索引 0,第二帧位于索引 1第三个位于索引 2.一旦选择了框架,所有WebDriver 接口上的后续调用是针对该框架进行的.

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.

  • 姓名或 ID.

    按名称或 ID 选择框架.按匹配名称定位的帧属性总是优先于 ID 匹配的那些.

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

  • 之前找到的WebElement.

    使用先前定位的 WebElement 选择一个框架.

    Select a frame using its previously located WebElement.

  • 通过 id/name 获取框架或通过 driver.findElement() 你会好的.

    Get the frame by it's id/name or locate it by driver.findElement() and you'll be good.

    这篇关于如何使用 Java 在 Selenium WebDriver 中的帧之间切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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