qileilove

          blog已經(jīng)轉(zhuǎn)移至github,大家請(qǐng)?jiān)L問(wèn) http://qaseven.github.io/

          Holmos自動(dòng)化測(cè)試入門學(xué)習(xí)(四)---------------iFrame里面元素的定位

           iFrame 定位的思想是先定位到iFrame,再定位iFrame里面的元素。
          常用到的3個(gè)方法:
          select()--------------------------選取要操作的frame
          selectParentContainer()  ------這個(gè)是回到上一層frame的 
          selectTopPage() ----------------這個(gè)是回到頂部頁(yè)面
           
          具體例子:
          1.新建2個(gè)html 頁(yè)面,放于D盤,作為被測(cè)試的頁(yè)面
          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.新建一個(gè)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頁(yè)面";  
          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. }  


          新建一個(gè)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();// 控制器交還給最底層頁(yè)面  
          15.        }  
          16. }  

          執(zhí)行結(jié)果:

          控制臺(tái)輸出:
          多層iFrame定位思想是一個(gè)樣的,一層一層往里邊定位。
          更多0

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


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          <2025年8月>
          272829303112
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 洛扎县| 鹿泉市| 昌图县| 新余市| 普安县| 长汀县| 瑞金市| 武冈市| 泗水县| 右玉县| 周宁县| 拉孜县| 西畴县| 兰坪| 广东省| 沙田区| 高台县| 昌平区| 麻阳| 临安市| 定南县| 阳新县| 韶关市| 阳原县| 永春县| 永嘉县| 西和县| 唐海县| 宣汉县| 襄樊市| 磴口县| 桓仁| 罗定市| 樟树市| 玛纳斯县| 镇巴县| 津南区| 邯郸市| 桑植县| 天气| 海伦市|