通过在TestCafe中包含文本来选择元素

时间:2020-07-03 14:44:38

标签: testing dom automated-tests e2e-testing testcafe

如何选择包含特定文本的HTML元素?

在Selenium中使用Xpath选择器,但TestCafe不支持Xpath。

我如何在TestCafe中做到这一点?

2 个答案:

答案 0 :(得分:0)

根据官方的documentation,为了选择包含特定文本的元素,我应该对所选元素使用.withText()方法,给出的示例是:

import { Selector } from 'testcafe';

fixture `Example`
    .page `https://devexpress.github.io/testcafe/example/`;

test('Click test', async t => {
    const selectBasedOnText = Selector('label').withText('I have tried TestCafe');

    await t
        .click(selectBasedOnText);
});

用于选择文本为“我已经尝试过TestCafe”的label元素。

答案 1 :(得分:0)

不, testcafe 支持 xpath

https://github.com/Programmingarea/XpathSelectorIhaveNotCreated

下载 xpath 选择器 下载后 转到您的 testcafe 文件并输入:

导入 xpath-selector

import XPathSelector from './xpath-selector';

使用:

const usingxpath = XPathSelector("your xpath");

简单! 如有疑问请回复

相关问题