我正在尝试从 Chrome 上的模式中获取文本.使用控制台,我可以得到如下内部文本:
I'm trying to get a text from a modal on Chrome. Using the console, I can get the inner text as follows:
document.querySelector('.my-form > a').innerText
// returns http://a-url.com
现在,在我的测试中,我可以使用评估元素
Now, on my test, I can evaluate the element using
const myText = Selector('.my-form > a').innerText;
await t
.expect(myText).contains('url');
我什至可以点击那个网址
and I can even click on that URL
await t.click(myText);
但例如,我不能将该内部文本放入变量中.我尝试使用 这篇文章
but I cannot put that inner text to a variable, for instance. I tried using a ClientFunction from this post
const getUrl = ClientFunction(() => document.querySelector('.my-form > a').innerText);
test('My Test', async t => {
const text = await getUrl();
console.log(text);
});
// this results in
// TypeError: Cannot read property 'innerText' of null
并尝试使用普通选择器作为 这篇文章建议
and tried using a plain Selector as this post suggests
const text = Selector('.my-form > a').innerText;
const inner = await text.textContent;
console.log(inner);
// prints: undefined
如何从元素中提取文本?我知道 t.selectText 在这种情况下是有限的,对吧?
How to extract a text from an element? I understand that t.selectText is limited in this scenario, right?
来自 文档 你想要的:
const text = await Selector('.my-form > a').innerText;
这篇关于Testcafe 从元素中获取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
在 Angular 2/Typescript 中使用 IScrollUse IScroll in Angular 2 / Typescript(在 Angular 2/Typescript 中使用 IScroll)
Anime.js 在 Ionic 3 项目中不起作用anime.js not working in Ionic 3 project(Anime.js 在 Ionic 3 项目中不起作用)
Ionic 3 - 使用异步数据更新 ObservableIonic 3 - Update Observable with Asynchronous Data(Ionic 3 - 使用异步数据更新 Observable)
Angular 2:在本地 .json 文件中找不到文件Angular 2: file not found on local .json file(Angular 2:在本地 .json 文件中找不到文件)
在 Ionic 2 中,如何创建使用 Ionic 组件的自定义指In Ionic 2, how do I create a custom directive that uses Ionic components?(在 Ionic 2 中,如何创建使用 Ionic 组件的自定义指令?)
将 ViewChild 用于动态元素 - Angular 2 &离子2Use ViewChild for dynamic elements - Angular 2 amp; ionic 2(将 ViewChild 用于动态元素 - Angular 2 amp;离子2)