从在testcafe中打开的第N个模式中选择“确定”按钮

时间:2019-03-26 20:12:36

标签: javascript html automated-tests e2e-testing testcafe

我在测试中打开了两个模态,我希望能够单击第二个模态(在下面的html中选择第二个元素)中的“确定”按钮。

我当前的代码是:

import { waitForReact } from 'testcafe-react-selectors';
import { Selector } from 'testcafe';

fixture `App tests`
    .page('http://localhost:3000/')
    .beforeEach(async () => {
        await waitForReact();
    });

test('Can open and accept all pop ups', async t => {

    //open first modal
    await t
        .click('#LayerAddingPopUpButtonID');

    //select OK button from first modal
    const modalOKButton = Selector('div.ant-modal')
        .find('div.ant-modal-footer')
        .find('button.ant-btn-primary');

    //click OK button from first modal
    await t
        .expect(modalOKButton.with({visibilityCheck: true}).exists)
        .ok({timeout: 30000})
        .hover(modalOKButton)
        .click(modalOKButton);

    //open second modal
    await t
        .click('#LayerDeletingPopUpButtonID');

    //select OK button from second modal
    const secondModalOKButton = Selector(??);
});

我正在使用的html如下。我正在尝试选择第二个“确定”按钮:

enter image description here

1 个答案:

答案 0 :(得分:5)

您尝试使用nth吗?

const modalOKButton = Selector('div.ant-modal').nth(1)
        .find('div.ant-modal-footer')
        .find('button.ant-btn-primary');

或者也许尝试通过aria-labelledby

使用选择器
const modalOKButton = Selector("[aria-labelledby='rcDialogTitle1']")
        .find('div.ant-modal-footer')
        .find('button.ant-btn-primary');