qileilove

          blog已經轉移至github,大家請訪問 http://qaseven.github.io/

          Holmos自動化測試入門學習(四)---------------iFrame里面元素的定位

           iFrame 定位的思想是先定位到iFrame,再定位iFrame里面的元素。
          常用到的3個方法:
          select()--------------------------選取要操作的frame
          selectParentContainer()  ------這個是回到上一層frame的 
          selectTopPage() ----------------這個是回到頂部頁面
           
          具體例子:
          1.新建2個html 頁面,放于D盤,作為被測試的頁面
          main.html
          1. <html>  
          2.     <head >  
          3.         <title> FrameTest</title >  
          4.     </head >  
          5.     <body >  
          6.         <div id = "id1"> this is a div !</ div>  
          7.         <iframe id = "frame"  frameborder="0" scrolling="no" style="left :0; position:absolute;" src = "iframe.html"></ iframe>  
          8.     </body >  
          9. </html><span style="font-family: Tahoma;"> </span>  
          iframe.html
          1. <html>  
          2.     <head >  
          3.         <title> this is a frame!</title >  
          4.     </head >  
          5.     <body >  
          6.         <div id = "div1"> this is a div !oo! </div>  
          7.         <label> input:</label >  
          8.         <input id = "input1"></ input>  
          9.     </body >  
          10. </html>  

          2.新建一個Page類,例子類目為P.java,代碼如下:
          1. import com.holmos.webtest.element.TextField;  
          2. import com.holmos.webtest.struct.Frame;  
          3. import com.holmos.webtest.struct.Page;  
          4.   
          5. public class P extends Page {  
          6.         public P() {  
          7.                super();  
          8.                this.comment = "iframe頁面";  
          9.                this.init();  
          10.        }  
          11.         // 先定位Frame  
          12.         public IFrameTest frame = new IFrameTest( "iframe");  
          13.        {  
          14.                frame.addIDlocator("frame" );// frame定位用ID定位  
          15.        }  
          16.         // 定位Frame里面的元素  
          17.         public class IFrameTest extends Frame {  
          18.                public IFrameTest(String comment) {  
          19.                       super(comment);  
          20.               }  
          21.                public TextField input = new TextField( "輸入框" );// 定位里面的輸入框  
          22.               {  
          23.                       input.addIDLocator("input1" );  
          24.               }  
          25.        }  
          26. }  


          新建一個Test類,例子類目為P_Test,代碼如下:
          1. import org.junit.Test;  
          2.   
          3. import com.holmos.webtest.EngineType;  
          4. import com.holmos.webtest.utils.HolmosWindow;  
          5.   
          6. public class P_Test {  
          7.         public P p = new P();  
          8.   
          9.         @Test  
          10.         public void input() {  
          11.               HolmosWindow. openNewWindow(EngineType.WebDriverChrome, "D:\\main.html" );  
          12.                p.frame .select();// 選取要操作的frame  
          13.                p.frame .input.setText( "試試看!能不能輸入" );// 操作frame里面的元素  
          14.                p.frame .selectTopPage();// 控制器交還給最底層頁面  
          15.        }  
          16. }  

          執行結果:

          控制臺輸出:
          多層iFrame定位思想是一個樣的,一層一層往里邊定位。
          更多0

          posted on 2014-05-12 16:09 順其自然EVO 閱讀(265) 評論(0)  編輯  收藏 所屬分類: HOLMOS


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 岳西县| 临泽县| 同仁县| 西峡县| 福州市| 卓尼县| 诸暨市| 镇江市| 仁布县| 班玛县| 乐亭县| 巢湖市| 合川市| 石首市| 蒙山县| 济源市| 雷州市| 连城县| 普洱| 留坝县| 永靖县| 富宁县| 福州市| 宁晋县| 衡东县| 古田县| 孟村| 开封市| 临朐县| 云林县| 电白县| 洛川县| 嵊泗县| 平江县| 合阳县| 三河市| 沧州市| 柏乡县| 阳城县| 邢台市| 吉木乃县|