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

如何使用 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.