我正在使用带有 WebDriver 的 java。我必须在两个帧之间切换。我已经在 selenium IDE 中记录了测试用例,其中我得到的值是 selectFrame relative=top select Frame=middle Frame
但是有一个问题是它无法识别 relative=top 和 middleFrame。如何使用 Java 在 Selenium WebDriver 中解决这个问题?
最佳答案
WebDriver 的 driver.switchTo().frame()
方法采用三个可能的参数之一:
-
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 index1
and the third at index2
. Once the frame has been selected, all subsequent calls on the WebDriver interface are made to that frame. -
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/