Select 元素通过在 TestCafe 中包含文本

Select element by containing text in TestCafe

如何 select 一个包含特定文本的 HTML 元素?

在 Selenium Xpath 中使用了 selector,但 TestCafe 不支持 Xpath。

如何在 TestCafe 中进行操作?

根据官方documentation,为了select一个包含特定文本的元素,我应该对selected元素使用.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);
});

select使用文本“我试过 TestCafe”的 label 元素。

不, testcafe 支持 xpath

https://github.com/Programmingarea/XpathSelectorIhaveNotCreated

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

正在导入 xpath 选择器

import XPathSelector from './xpath-selector';

使用它:

const usingxpath = XPathSelector("your xpath");

简单! 如有疑问请回复

对我有用的:

import xPathToCss from 'xpath-to-css'

然后用作 ex:

.click(xPathToCss("//a[@class='icon-menu login show-login-panel list-item list-item-next']"));