javascript - 单击动态生成的按钮
问题描述
我将给出“从日期”和“到日期”并点击“创建”按钮。预期的输出是
- 从“从日期”到“到日期”找到 N 个案例,带有下载按钮
- 从“从日期”到“到日期”找到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 个案例......”然后什么也不做,或者如果找到案例,然后单击动态生成的下载按钮。
解决方案
请尝试以下代码段,
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");
}
});
干杯!
推荐阅读
- java - Postgresql:作为Java本机查询中的查询输入的空值抛出运算符不存在:字符变化= bytea异常
- android - 在 Android for Work 应用程序中访问联系人
- javascript - 如何在节点js中定义对象
- media - 没有有效的比特率:Roku 播放器中的错误 -5
- validation - SwiftUI:它如何刷新视图以及为什么 @Published ObservableObject 属性随机工作
- python - Tensorflow 给出错误 ImportError: DLL load failed with error code -1073741795
- android - Android Firefox 在后台不显示网络推送消息
- ajax - 如何使用 AJAX 在弹出窗口中显示 wpDataTables 结果
- javascript - 如何在当前视图中加载新视图?
- wpf - 我怎样才能在屏幕上获取所有价值?