[英]Testcafe, how to click a button on a modal popup?
我正在努力在 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')
但您还没有声明是class
(.) 还是id
(#)。
所以你的构造函数变量应该是:
this.modal_popup = Selector('.panel-body center')
^
This
如果你不使用.
或#
,TestCafe 将查找值作为标签( div
, button
...)并且panel-body
不是标签,是类名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.