English 中文(简体)
Watir - Working with Iframes
  • 时间:2024-03-18 23:05:20

Watir - Working with Iframes


Previous Page Next Page  

Watir很容易利用yn子与 if子合作。

Syntax

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

为了了解如何处理金字塔和确定仪表内各项要素,我们将以实例开展工作。

Example

main.html

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

test1.html

<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>
      
      <span id = "spanfirstname">
         Enter First Name : 
         <input type = "text" id = "firstname" name = "firstname" onchange = "wsentered()" />
      </span>
      <br/>
      <br/>
         <span style = "display:none;" id = "displayfirstname"></span>
   </body>
</html>

Output

Iframe

在上述例子中,入境表格在一行内界定。 瓦伊夫法典将帮助我们找到并测试表格。

Watir Code

require  watir 
b = Watir::Browser.new :chrome
b.goto( http://localhost/uitesting/main.html )
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 

瓦伊夫法典,将iframe放在此处的圆顶上——

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

我们使用了上面所示的标签框架和仪表。

以上准则的筛选情况如下:

iframetestbefore.png

Using ID

iframetestafter.png

Using ID Element

Advertisements