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)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 淳化县| 浦东新区| 涟源市| 信宜市| 兰考县| 固原市| 雷山县| 大埔区| 德惠市| 太仓市| 罗田县| 岳池县| 石棉县| 江永县| 冷水江市| 杂多县| 麻江县| 茂名市| 石渠县| 双柏县| 文山县| 鲁山县| 衡水市| 普定县| 海阳市| 吉木萨尔县| 德昌县| 邵武市| 扶风县| 广饶县| 刚察县| 马尔康县| 营口市| 舞阳县| 曲周县| 永泰县| 永兴县| 古丈县| 龙陵县| 习水县| 丰都县|