我是硒的新手..
我有一个创建帐户的主页。如果我点击创建帐户弹出我输入电子邮件地址和密码并提交按钮。
我在下面使用了导航到第一个iframe。
driver.switchTo().frame(0);
这对我来说非常合适。
点击iframe 1上的提交按钮,还有另一个iframe,它显示我输入firstName,lastName,gender和One time passsword。
我正在使用下面的代码段导航到iframe并输入firstName。它无法正常工作
driver.switchTo().defaultContent();
driver.switchTo().frame("login-iframe");
driver.findElement(By.xpath("//input[@id='fname']")).sendKeys("Test");
任何人都可以告诉我它是否正确?我已经尝试设置回defaultContent而不是设置为defaultContent()两个..
此处的源代码:
<iframe id="login-iframe" style="width: 800px;height: 530px;">
</iframe></div></div>
<div id="user-verify-modal" class="md-modal md-effect-10">
<div class="md-content">
<!-- a.close(href="#")-->
<div class="tab-links">
<ul>
<li data-type="" class="hidden active">
<a href="#new-wallet"> Complete your details to create XXX Cash Wallet</a>
<span class="arrow arrow-filled">
</span>
</li>
</ul>
<div class="logo pull-right">
</div>
<div class="clear">
</div>
</div>
<div class="tab-content">
<div id="new-wallet" class="tab-pane active">
<div class="pull-left border-rt">
<div class="row">
<div class="first">
<label>First name </label>
<input id="fname" type="text" value="" name="fname" maxlength="25"/>
<span class="blankfirstName">Enter your First Name</span>
</div>
<div>
<label>Last name</label>
<input id="lname" type="text" value="" name="lname" maxlength="25"/>
</div>
</div>
<div class="row radiobuttons">
<label><input id="male" type="radio" name="gender" value="Male"/>Male</label>
<label><input id="female" type="radio" name="gender" value="Female"/>Female</label>
</div>
<div class="row emailrow"><em class="verified"><i></i>Verified</em>
<input id="userEmail" type="text" value="" name="userEmail"/>
<span class="blankemail">Enter your Email where we will send you a verification link once you proceed</span>
<span class="invalidemail">Enter a valid Email where we will send you a verification link once you proceed</span>
<span class="invalidEmailEntered">The entered Email is invalid. Please enter a valid Email where we will send you a verification link once you procced.</span>
<span class="duplicateEmail">We already have a XXX account with this Email. Enter a different Email or Sign in using this.</span>
<span class="errorEmail">Sorry, there's been an error sending mail.</span>
</div>
<div class="row changeEmailContent">We have sent a verification link to <b> </b>. Please verify the same once you proceed or <a href="javascript:void(0);" class="changemail">Change Email</a>
</div>
<div class="row mobilerow"><em class="verified"><i></i>Verified</em><label>Mobile number </label>
<input id="userNumber" type="text" value="" name="userNumber" maxlength="10"/>
<span class="blankNumber">Enter your Mobile</span><span class="invalidNumber">Enter a valid Mobile</span>
<span class="invalidNumberEntered">The entered Mobile is incorrect, update this to verify the new Mobile</span>
<span class="duplicateNumber">This Mobile exists in other xXXX accounts. Update this and to verify the new Mobile</span>
<span class="errorNumber">Sorry, there's been an error sending OTP.</span>
</div>
<div class="row changeMobileContent">Enter One Time Password (OTP) sent to your Mobile <b> </b> or <a href="javascript:void(0);" class="changmobile">Change Mobile</a></div><div class="row enterOTP"><a href="javascript:void(0);" class="sendotp">Resend OTP</a>
<label>Enter OTP</label>
<input id="enterOTP" type="text" name="enterOTP" value="" maxlength="6"/>
<span class="error"></span>
<span class="otpsent">One Time Password (OTP) has been resent. If you still do not receive the OTP within 15 minutes, please contact us at <a href="mailto:care@xxx.com">care@xxx.com</a></span>
</div>
<div style="margin-bottom:0px;" class="row"><div class="first"><button id="skipVerifyDetails" type="submit" class="btn btn-primary">Skip</button>
</div>
<div><button id="confirmVerifyDetails" type="submit" class="btn btn-primary">Confirm</button></div>
答案 0 :(得分:1)
从您的html来源看,标识input
的{{1}}似乎不属于名为fname
的{{1}},因为它已结束且iframe
为低于默认内容。
login-iframe
所以我认为你应该在input
内搜索输入。你试过这个吗?
<iframe id="login-iframe" style="width: 800px;height: 530px;">
</iframe>
在旁注中,您只能使用defaultContent
代替driver.switchTo().defaultContent();
driver.findElement(By.xpath("//input[@id='fname']")).sendKeys("Test");
来查找元素,因为它具有ID。