首页 > 解决方案 > 单击动态生成的按钮

问题描述

我将给出“从日期”和“到日期”并点击“创建”按钮。预期的输出是

  1. 从“从日期”到“到日期”找到 N 个案例,带有下载按钮
  2. 从“从日期”到“到日期”找到0个没有下载按钮的案例

在第一种情况下:

<div data-ng-if="canDownload()" class="ng-scope"
<h3 class="ABC" id="summary">N cases ound from "from dates" to "to dates"
<a data-ng-href="URL" id="summaryHREF"
<button class="XYZ" type="submit">Download<

在第二种情况下:

<div data-ng-if="noCases()" class="ng-scope"
<h3 class="ABC" >0 cases ound from "from dates" to "to dates"

我成功地测试了正面场景(发现案例)

let notes = element(by.id("summary"));

var EC = protractor.ExpectedConditions;
var flag = browser.wait(EC.visibilityOf(notes), 5000, '**** There are cases to Download ****');

if(flag){

  this.downloadReg = element(by.xpath("//button[text()='Download']"));
  this.downloadReg.click();
}
else{
  console.log("No Cases found and Do Nothing");

}

如何检查“摘要”文本是否包含“找到 0 个案例......”然后什么也不做,或者如果找到案例,然后单击动态生成的下载按钮。

标签: javascriptprotractorgulp-protractor

解决方案


请尝试以下代码段,

browser.wait(EC.visibilityOf(element(by.css('#summary'))), 5000, '**** There are cases to Download ****').then(flag => {
      if(flag){
        this.downloadReg = element(by.xpath("//button[text()='Download']"));
        this.downloadReg.click();
      }else{
        console.log("No Cases found and Do Nothing");
      }
    });

干杯!


推荐阅读