如何使用Java在Selenium WebDriver中切换帧 [英] How to switch between frames in Selenium WebDriver using Java
问题描述
我正在使用带有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()。帧()
方法接受三个可能的参数之一:
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 index1
and the third at index2
. Once the frame has been selected, all subsequent calls on the WebDriver interface are made to that frame.
按名称或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选择一个框架。
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屋!