首先,我点击邮件发送者电子邮件上的超链接,然后在我添加到屏幕截图中的同一窗口中打开新标签和弹出窗口。
有时此代码在制表符刷新后工作,但同一时间事件不刷新也无效。我希望有时候driver.switchTo()。window(winHandle);不正常。
HTML代码:
<div id="zDeskPasswordConfirm" class="modal fade ng-scope in" role="dialog" data-keyboard="false" data-backdrop="static" tabindex="-1" style="display: block;">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header portal-header">
<button class="close" aria-label="Close" ng-click="close()" data-target="#zDeskSignup" data-dismiss="modal" type="button">
<div>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-offset-1 col-md-10">
<form id="passwordConfirmationForm" class="form-horizontal ng-pristine ng-valid-email ng-invalid ng-invalid-required ng-valid-pattern" novalidate="" name="passwordConfirmationForm">
<div class="form-group">
<label class="ng-bind-htmling" ng-bind-html="translation.login_email">Email</label>
<div class="input-group">
<span id="basic-addon1" class="input-group-addon">
<input id="email" class="form-control ng-pristine ng-untouched ng-valid-email ng-valid-pattern ng-not-empty ng-valid ng-valid-required" type="email" required="" disabled="disabled" placeholder="Email" ng-model="confirm.Email" ng-pattern="/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/" name="email"/>
</div>
</div>
<div class="form-group">
<label class="ng-bind-htmling" ng-bind-html="model.PH_Password">Password</label>
<div class="input-group">
<span id="basic-addon1" class="input-group-addon">
<input id="newPassword" class="form-control ng-pristine ng-untouched ng-empty ng-invalid ng-invalid-required ng-valid-pattern" type="password" required="" placeholder="Password" ng-model="confirm.Password" name="password" ng-pattern="/(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}/"/>
</div>
<span class="ng-bind-htmling ng-hide" ng-bind-html="model.Error_Password" style="color:red" ng-show="passwordConfirmationForm.password.$invalid && submitted">Invalid Password Format (Ex : Admin123)</span>
</div>
<div class="form-group">
<label class="ng-bind-htmling" ng-bind-html="model.PH_RePassword">Confirm Password</label>
<div class="input-group">
<span id="basic-addon1" class="input-group-addon">
<input id="rePassword" class="form-control ng-pristine ng-untouched ng-isolate-scope ng-empty ng-invalid ng-invalid-required ng-valid-pattern" type="password" required="" placeholder="Confirm Password" data-password-verify="confirm.Password" ng-model="confirm.rePassword" name="rePassword" ng-pattern="/(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}/"/>
</div>
<span class="ng-bind-htmling ng-hide" ng-bind-html="model.Error_RePassword" style="color:red" ng-show="passwordConfirmationForm.rePassword.$invalid && submitted">Invalid Confirm Password.</span>
</div> <div class="text-center"> </form> </div> </div> </div> </div> </div> </div>
Selenium Code Here -
@Test (priority=5,enabled=true)
public void ConfirmationPw() throws Exception
{
for(String winHandle : driver.getWindowHandles()){
driver.switchTo().window(winHandle);
driver.navigate().refresh();
driver.findElement(By.xpath(prop.getProperty("NewPassWordSet"))).sendKeys(prop.getProperty("password2"));
driver.findElement(By.xpath(prop.getProperty("ComfPassWordSet"))).sendKeys(prop.getProperty("password"));
driver.findElement(By.xpath(prop.getProperty("PasswordConfirmationActiveButton"))).click();
}
}