javascript - Testcafe,如何单击模式弹出窗口上的按钮?
问题描述
我正在努力在 TestCafe 中定义一个选择器,该选择器单击左侧名为“开始汽车损坏索赔”的按钮。此按钮出现在模式弹出窗口中。
我的代码看起来像
class PortalDashboard {
constructor(){
//Selectors Portal
this.welcome_user_message = Selector('#welcomeBack')
this.topbar = Selector('#stateNavbar')
this.footer = Selector('.row footerSectionOne')
this.policy_summary = Selector('#policySummaryList')
this.logout_button = Selector('.logoutBtn')
this.my_claims = Selector('a[href="./claims"]')
this.view_motor_policy_details_link = (Selector('#policySummaryDetails_M0014157733').find('#claimLink_0'))
//Start a claim - Modal popup
this.motor_claim_modal = Selector ('#carAccidentDialog')
this.property_claim_modal = Selector('.claimDialog')
this.call_us_button = Selector('#callUsDesktop')
this.start_claim_button = Selector('#defaultFocus')
this.modal_popup=Selector('panel-body center')
}
async clickStartClaim(claimtype){
await t
.expect(this.modal_popup.exists).ok('Element not found', { timeout: config.general.shortTimeout })
.expect(this.call_us_button.exists).ok('Element not found', { timeout: config.general.shortTimeout })
.expect(this.start_claim_button.innerText).contains(claimtype)
.click(this.start_claim_button)
.setPageLoadTimeout(config.general.shortTimeout )
}
TestCafe 目前无法在modal_popup
弹出窗口中找到选择器。
我可以使用哪个选择器以便 Testcafe 可以找到弹出窗口然后单击按钮?
显示错误:
1) AssertionError: Element not found: expected false to be truthy
async clickStartClaim(claimtype){
88 | await t
> 89 | .expect(this.modal_popup.exists).ok('Element not found', { timeout: config.general.shortTimeout })
解决方案
我认为您的问题不在于按钮本身,而在于模式。请注意,错误在断言中:
.expect(this.modal_popup.exists).ok
您的modal_popup
变量是Selector('panel-body center')
,但您尚未声明 if 是class
(.) 或id
(#)。
所以你进入构造函数的变量应该是:
this.modal_popup = Selector('.panel-body center')
^
This
如果您不使用.
or #
,TestCafe 将查找值作为标记 ( div
, button
...) 并且panel-body
不是标记,是类名。
推荐阅读
- excel - 发生错误 9 时的 VBA 不显示错误消息
- reactjs - nextjs 网站在直接链接到页面或动态路由时一直显示 403
- c# - 方法中的 C# 字符串为空
- python - 启用 Google IAM API Python
- tensorflow - 将 keras 模型转换为 tflite 时出错
- python - 反转列表中的“行”
- python - 如果我已经在使用上下文管理器,如何关闭 Pandas ExcelWriter 对象(我应该这样做吗?)
- python - Python Exchangelib 阅读附加的电子邮件
- python - 如何在pyqt5中向菜单栏添加分隔符
- kubernetes - Kubernetes 节点 OOM 和 Node Allocator 的 systemReserved 设置