javascript - 无法在 "Type to search dropdown"中输入文本,这是使用 testcafe 的 react 组件

标签 javascript reactjs automated-tests e2e-testing testcafe

无法在“键入搜索下拉列表”中键入文本,这是一个 react 组件。我可以单击该组件,但无法在其中输入任何文本。 下面是示例代码。

import { Selector } from 'testcafe';

test('Select option', async t => {

    const dropdown = Selector('.section')
                .find('.Select.is-clearable.is-searchable.Select--multi')
                .find('.Select-control')
                .find('.Select-placeholder')
                .withText('Select...');

    await t.click(dropdown);
    await t.typeText(dropdown, 'abc'); // unable to pass text 'abc'
    await t.wait(3000);
});

使用类似组件的示例站点 http://jedwatson.github.io/react-select/

最佳答案

const dropdown = Selector('.section')
            .find('.Select.is-clearable.is-searchable.Select--multi')
            .find('.Select-control')
            .find('.Select-placeholder')
            .withText('Select...');

const inputField = dropdown
    .sibling('.Select-input')
    .find('input');

await t
    // wait until element is visible on the screen
    .expect(dropdown.with({visibilityCheck: true}).exists).ok({timeout: 5000})
    // access the element via the mouse (will fire the mouse event onMouseEnter)
    .hover(dropdown)
    .click(dropdown)
    .typeText(inputField, 'abc');

关于javascript - 无法在 "Type to search dropdown"中输入文本,这是使用 testcafe 的 react 组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53777913/

相关文章:

javascript - "Incremented"元素中的 CSS 类

android - React Native Android 生产版本仍然像开发版本一样

javascript - Axios 仅在自调用函数中调用一次 (Internet Explorer)

javascript - 在所有屏幕宽度上应用第 n 个 child

javascript - 将 Jquery 选择器的名称设置为变量中的字符串

javascript - 隐藏 ajax append 的 html 直到某个点

javascript - PrimeNG Autocomplete 不通过输入搜索查询显示任何建议

testing - AEM Workflows 的自动化测试

javascript - 如何单击具有特定文本列的表格行的元素?

testing - Robot Framework - 使用相对路径从不同的目录变体运行测试