Testcafe:如何不从 html 代码(选择器)而是在 UI 上的字段中获取文本
Testcafe: How to grab the text not from html code (selector) but in field on UI
我需要从 UI 字段(输入)中写入的文本中提取部分字符串(此文本不在 HTML 代码中)。
我正在尝试这样的事情(但它不起作用)。
const textInput = await model.inputtTittle.textContent;
console.log(textInput)
什么都没有 return 可能是 textContent 从选择器中获取文本,我正在尝试使用 .innerText 但它也 return 什么也没有。
然后我想这样写:
if (textInput.length > 32)
await t.typeText(model.inputTittle, textInput.substr(0, 30));
如果我有inputTittle字段的内容希望能成功
附加问题:
此答案已隐藏。 Jason Aller、Mark Rotteveel、Nico Haase、Botje 在 16 小时前通过评论删除了此答案。
此代码有效:
const textTittle = await model.inputTittle.value;
const textlength = textTittle.length
if (textlength>32)
{
console.log(textTittle.substr(0,30));
}
为什么我不能写得更短:
如果(等待model.inputTittle.value.length>32)
{ console.log(await model.inputTittle.value.substr(0,30));}
您可以获得整个DOM Node Snapshot with all properties in one object to check what properties you need. It is likely you need the value
property。
我需要从 UI 字段(输入)中写入的文本中提取部分字符串(此文本不在 HTML 代码中)。 我正在尝试这样的事情(但它不起作用)。
const textInput = await model.inputtTittle.textContent;
console.log(textInput)
什么都没有 return 可能是 textContent 从选择器中获取文本,我正在尝试使用 .innerText 但它也 return 什么也没有。
然后我想这样写:
if (textInput.length > 32)
await t.typeText(model.inputTittle, textInput.substr(0, 30));
如果我有inputTittle字段的内容希望能成功
附加问题:
此答案已隐藏。 Jason Aller、Mark Rotteveel、Nico Haase、Botje 在 16 小时前通过评论删除了此答案。 此代码有效:
const textTittle = await model.inputTittle.value;
const textlength = textTittle.length
if (textlength>32)
{
console.log(textTittle.substr(0,30));
} 为什么我不能写得更短:
如果(等待model.inputTittle.value.length>32)
{ console.log(await model.inputTittle.value.substr(0,30));}
您可以获得整个DOM Node Snapshot with all properties in one object to check what properties you need. It is likely you need the value
property。