Holmos自动化测试入门学习(四)---------------iFrame里面元素的定位

来源:互联网 发布:java虚拟机规范 编辑:程序博客网 时间:2024/06/01 23:31
 iFrame 定位的思想是先定位到iFrame,再定位iFrame里面的元素。

常用到的3个方法:
select()--------------------------选取要操作的frame
selectParentContainer()  ------这个是回到上一层frame的 
selectTopPage() ----------------这个是回到顶部页面
 

具体例子:
1.新建2个html 页面,放于D盘,作为被测试的页面
main.html
<html>    <head >        <title> FrameTest</title >    </head >    <body >        <div id = "id1"> this is a div !</ div>        <iframe id = "frame"  frameborder="0" scrolling="no" style="left :0; position:absolute;" src = "iframe.html"></ iframe>    </body ></html> 
iframe.html
<html>    <head >        <title> this is a frame!</title >    </head >    <body >        <div id = "div1"> this is a div !oo! </div>        <label> input:</label >        <input id = "input1"></ input>    </body ></html>


2.新建一个Page类,例子类目为P.java,代码如下:
import com.holmos.webtest.element.TextField;import com.holmos.webtest.struct.Frame;import com.holmos.webtest.struct.Page;public class P extends Page {        public P() {               super();               this.comment = "iframe页面";               this.init();       }        // 先定位Frame        public IFrameTest frame = new IFrameTest( "iframe");       {               frame.addIDlocator("frame" );// frame定位用ID定位       }        // 定位Frame里面的元素        public class IFrameTest extends Frame {               public IFrameTest(String comment) {                      super(comment);              }               public TextField input = new TextField( "输入框" );// 定位里面的输入框              {                      input.addIDLocator("input1" );              }       }}



新建一个Test类,例子类目为P_Test,代码如下:
import org.junit.Test;import com.holmos.webtest.EngineType;import com.holmos.webtest.utils.HolmosWindow;public class P_Test {        public P p = new P();        @Test        public void input() {              HolmosWindow. openNewWindow(EngineType.WebDriverChrome, "D:\\main.html" );               p.frame .select();// 选取要操作的frame               p.frame .input.setText( "试试看!能不能输入" );// 操作frame里面的元素               p.frame .selectTopPage();// 控制器交还给最底层页面       }}


执行结果:

控制台输出:



多层iFrame定位思想是一个样的,一层一层往里边定位。

原创粉丝点击