简体   繁体   English

Testcafe,如何单击模式弹出窗口上的按钮?

[英]Testcafe, how to click a button on a modal popup?

I'm struggling to define a selector in TestCafe that clicks that button on the left called "start a car damage claim".我正在努力在 TestCafe 中定义一个选择器,该选择器单击左侧名为“开始汽车损坏索赔”的按钮。 This button appears on a modal popup .此按钮出现在模态弹出窗口中。 在此处输入图片说明

My code looks like我的代码看起来像

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 fails at the moment to find the selectors modal_popup on the popup. TestCafe 目前无法在弹出窗口中找到选择器modal_popup

Which selector can I use so Testcafe can find the popup and then click the button?我可以使用哪个选择器,以便 Testcafe 可以找到弹出窗口,然后单击按钮?

Error displayed:显示错误:

   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 })

I think your problem is not with the button itself but with the modal.我认为您的问题不在于按钮本身,而在于模态。 Note that the error is in the assertion:请注意,错误在断言中:

.expect(this.modal_popup.exists).ok .expect(this.modal_popup.exists).ok

Your modal_popup variable is Selector('panel-body center') but you have not declared if is class (.) or id (#).您的modal_popup变量是Selector('panel-body center')但您还没有声明是class (.) 还是id (#)。

So your variable into constructor should be:所以你的构造函数变量应该是:

this.modal_popup = Selector('.panel-body center')
                             ^
                            This

If you don't use .如果你不使用. or # , TestCafe will look for the value as tag ( div , button ...) and panel-body is not a tag, is a class name.# ,TestCafe 将查找值作为标签( divbutton ...)并且panel-body不是标签,是类名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM