Watir-working-with-iframes

提供:Dev Guides
移動先:案内検索

Watir-iframeの使用

Watirは、iframeを操作するための使いやすい構文を提供します。

構文

browser.iframe(id: 'myiframe')
//will get the reference of the iframe where we want to input details.

iframeの処理方法を理解し、iframe内の要素を見つけるために、この章では例に取り組みます。

メイン

<html>
   <head>
      <title>Testing using Watir</title>
   </head>
   <body>
      <iframe src = "test1l" id = "myiframe" width = "500" height = "100"></iframe>
   </body>
</html>

テスト1

<html>
   <head>
      <title>Testing UI using Watir</title>
   </head>

   <body>
      <script type = "text/javascript">
         function wsentered() {
            console.log("inside wsentered");
            var firstname = document.getElementById("firstname");

            if (firstname.value != "") {
               document.getElementById("displayfirstname").innerHTML =
                  "The name entered is : " + firstname.value;

               document.getElementById("displayfirstname").style.display = "";
            }
         }
      </script>

      <div id = "divfirstname">
         Enter First Name :
         <input type = "text" id = "firstname" name = "firstname" onchange = "wsentered()"/>
      </div>
      <br/>
      <br/>
         <div style = "display:none;" id = "displayfirstname"></div>
   </body>
</html>

出力

iframe

上記の例では、エントリフォームはiframe内で定義されています。 私たちがそれを見つけてフォームをテストするのに役立つWatirコードを以下に示します-

ワティアコード

require 'watir'
b = Watir::Browser.new :chrome
b.goto('http://localhost/uitesting/mainl')
t = b.iframe(id: 'myiframe').text_field
t.set 'Riya Kapoor'
b.screenshot.save 'iframetestbefore.png'
t.fire_event('onchange')
b.screenshot.save 'iframetestafter.png'

ここで指定されたURLでiframeを見つけるためのワティアコード-

t = b.iframe(id: 'myiframe').text_field

上記のように、iframeのタグ名とiframeのIDを使用しました。

上記のコードのスクリーンショットを以下に示します-

iframetestbefore.png

IDを使用

iframetestafter.png

ID要素の使用