无法访问 iframe 中的文本字段

Unable to access text field in an iframe

我正在尝试使用 Watir-Webdriver 自动执行测试脚本。在编写脚本时,我必须填写登录详细信息。现在它会是一个简单的 text_field,我知道语法并且会更容易。但是当我检查该页面上的元素时,我看到以下内容:

<div class="signin-part">

<iframe id="zohoiam" frameborder="0" allowtransparency="true" style="width:430px;height:350px;margin: 0;float:left" src="https://accounts.zoho.com/login?servicename=ZohoCRM&serviceu…o&hide_signup=true&css=https://www.zoho.com/css/prd-sign.css" scrolling="no" name="zohoiam" marginheight="0" marginwidth="0">
    #document
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1.dtd">
        <html>
            <head></head>
            <body class="bodycolor" onload="setlwh();">
                <noscript></noscript>
                <div id="enableCookie" class="loginNotes" style="display:none;"></div>
                <table id="outertable" class="mobile-login" width="100%" style="">
                    <tbody>
                        <tr valign="top"></tr>
                        <tr></tr>
                        <tr>
                            <td align="center">
                                <form id="msgOrgUserform" class="hide" method="post" name="msgOrgUserform"></form>
                                <div id="loginform">
                                    <div class="mobilelogo"></div>
                                    <form id="login" class="" novalidate="" method="post" onsubmit="javascript:return submitlogin(this);" name="login">
                                        <table id="inntbl" class="mob_width" cellspacing="0" cellpadding="0" align="center">
                                            <tbody>
                                                <tr>
                                                    <td valign="top">
                                                        <table class="mob_width" width="260" cellspacing="2" cellpadding="1" align="center">
                                                            <tbody>
                                                                <tr></tr>
                                                                <tr></tr>
                                                                <tr>
                                                                    <td class="label"></td>
                                                                    <td align="left">
                                                                        <input id="lid" class="input usrbx" type="email" onkeypress="clearmsg()" value="" name="lid"></input>
                                                                    </td>
                                                                </tr>

因此,如我所见,电子邮件字段位于 table -> 单元格内。所以我无法使用 Watir 访问它。我这样试过:

b.text_field(:id,'lid').set 'my value'

有人可以帮忙吗?

在下一行中,Watir 将在 iframe(和框架)中的 除了 的任何地方寻找元素。

b.text_field(:id,'lid').set 'my value'

与其他元素不同,当元素位于框架中时,您必须告诉 Watir。这与将元素搜索范围限定到特定元素的方式类似。

例如,如果只有一个iframe或者你的元素在第一个iframe中,你可以这样做(注意添加.iframe):

b.iframe.text_field(:id => 'lid').set 'my value'

如果有多个 iframe,您将需要添加参数以更具体地指定使用哪个 iframe。例如,框架有一个 id:

b.iframe(:id => 'zohoiam').text_field(:id,'lid').set 'my value'