【问题标题】:How to resolve “Element not visible” error shows for only one element in the popup.如何解决弹出窗口中仅显示一个元素的“元素不可见”错误。
【发布时间】:2017-01-17 07:36:23
【问题描述】:

所有属性形式相同但脚本到达最后一个元素显示“元素不可见错误”

同一级别 div 标签中的所有元素,但脚本运行单击事件(注册按钮)显示错误消息“元素不可见”。但是,除了提交按钮单击之外,我可以在其中填充数据并能够运行单击事件的所有其他字段也可以在弹出窗口中使用。问题我有弹出我添加截图图像。

此处为 HTML 代码

<form id="sighUpForm" class="form-signin ng-pristine ng-invalid ng-invalid-required ng-valid-pattern" novalidate="" name="sighUpForm">
<div class="row">
<div class="form-group">
<div class="form-group">
<div class="row">
<div class="form-group">
<label class="ng-bind-htmling" ng-bind-html="translation.signup_mobile">Mobile No.</label>
<div class="input-group">
<span class="error-msg ng-hide" style="color:red" ng-show="sighUpForm.PhoneNo.$invalid && submitted">
</div>
<div style="text-align:center;">
<label class="checkbox-inline ng-bind-htmling" style="line-height:1.8; font-size:12px">
<input class="ng-pristine ng-untouched ng-empty ng-invalid ng-invalid-required" type="checkbox" value="" ng-model="user.termAndCondition" required="" name="termAndcondition" style="height:15px; width:15px; margin-top:5px; margin-right:3px "/>
I agree to the 
<a data-target="#tandcmodal" data-toggle="modal" href="#">
 and 
<a data-target="#ppmodal" data-toggle="modal" href="#">
</label>
<br/>
</div>
<div class="text-center">
<!-- <small class="tc-text">By signing up, you agree to our <a href="#" data-toggle="modal" data-target="#tandcmodal">Terms &amp; Condions</a> and <a href="#" data-toggle="modal" data-target="#ppmodal">Privacy Policy</a></small><br />-->
<!--<button id="submitSignup" type="submit" ng-click="SignUpUser()" class="button signup-btn">Signup</button>-->
<a id="submitSignup" class="button signup-btn" ng-click="SignUpUser()">
</div>
</form>

这里的硒代码:-

//Enter PhoneNumber
     driver.findElement(By.xpath(prop.getProperty("SignUpPhoneNo"))).sendKeys(prop.getProperty("PhoneNumber"));
     Thread.sleep(500);

     //Click Agree Tick
     driver.findElement(By.xpath(".//*[@id='sighUpForm']/div[6]/label/input")).click(); 
     Thread.sleep(600);

     //Click Submit button
     driver.findElement(By.xpath(".//*[@id='submitSignup']/span")).click();

弹出图片:-

【问题讨论】:

  • 你想点击弹出的注册按钮吗??

标签: javascript jquery html css selenium


【解决方案1】:

您应该尝试使用WebDriverWait 等到元素可见且可点击。

您可以通过以下两种方式在此处提交表单:-

WebDriverWait wait = new WebDriverWait(driver,10);
  • 您可以使用.submit() 提交表单:-

    WebElement form = wait.until(ExpectedConditions.presenceOfElementLocated(By.id("sighUpForm")));
    form.submit();
    
  • 您可以使用.click()点击注册按钮提交表单:-

    WebElement signUp = wait.until(ExpectedConditions.elementToBeClickable(By.id("submitSignup")));
    signUp.click();
    

已编辑:- 可能有多个 ID 为 submitSignupsignUp 按钮,不幸的是,您正在与隐藏按钮进行交互,您应该尝试查找 ID 为 @ 的所有元素987654329@ 并点击可见的如下:-

List<WebElement> signUpButtons = wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.id("submitSignup")));
for(WebElement signUp : signUpButtons)
{
  if(signUp.isDisplayed() && signUp.isEnabled())
  {
    signUp.click();
  }
}

【讨论】:

  • 你的意思是没用??两种情况或其他情况是否有相同的例外?
  • 当我输入点击错误:- org.openqa.selenium.TimeoutException:20 秒后超时等待元素可点击:By.id:submitSignup 构建信息:版本:'2.52.0' ,修订:'4c2593c',时间:'2016-02-11 19:03:33' 系统信息:主机:'DESKTOP-PC1SJR4',ip:'192.168.0.105',os.name:'Windows 10',
  • 然后发生了什么??
  • 但提交运行没有错误但提交按钮不起作用
  • 好的,你能告诉我这个注册按钮什么时候可以手动显示和点击吗??
【解决方案2】:

在“注册”链接上尝试使用WebDriverWait 驱动程序和ExpectedConditionelementToBeClickable(By locator)。这将检查元素是否可见和可点击。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多