如何在同一div中的其他类中存在文本的情况下定义输入字段(选择器)

huangapple go评论63阅读模式
英文:

How to define input field (Selector) under condition to exist text in other class in the same div

问题

我在定义输入文本字段方面遇到了问题

this.requiredField = Selector('input').withAttribute('required');

在验证标签为

this.requiredLabel = Selector('.form-control-warning').withText('Required field cannot be left blank');

这些都在class="col-10"中 - 请参见下文

如何在同一div中的其他类中存在文本的情况下定义输入字段(选择器)

我对没有文本"Required field cannot be left blank"的字段不感兴趣。form-control-warning
如何在同一div中的其他类中存在文本的情况下定义输入字段(选择器)

我需要这个,因为我必须在具有标签'Required field cannot be left blank'的每个字段中输入文本。
我创建了类似这样的东西:

while (await epgBoard.requiredLabel.exists)
{
await t.typeText(epgBoard.emptyRequiredField, 'ff')
}

我不知道如何定义这样的选择器

this.emptyRequiredField =
在.col-10中查找 -> input,其中带有属性required且.form-control-warning中有文本"Required field cannot be left blank"

有人可以帮我解决这个问题吗?

英文:

I'm having trouble defining the field for typing text into

this.requiredField = Selector('input').withAttribute('required');

in a condition where the validation label is

this.requiredLabel = Selector('.form-control-warning').withText('Required field cannot be left blank');

There are in class=”col-10” – see below

如何在同一div中的其他类中存在文本的情况下定义输入字段(选择器)

I am not interested in such a filed where there is no text Required field cannot be left blank in. form-control-warning
如何在同一div中的其他类中存在文本的情况下定义输入字段(选择器)

I need it because I must type text in each field with a label: 'Required field cannot be left blank"
I created sth like this:

while (await epgBoard.requiredLabel.exists)
{

await t.typeText(epgBoard.emptyRequiredField, 'ff')
}

I have no idea how to define such selector

this.emptyRequiredField =
find in .col-10 -> input withAtrribute required where . form-control-warning has text Required field cannot be left blank

Could sb help me with this matter?

答案1

得分: 1

withText 方法用于筛选包含指定文本的现有DOM节点。例如:

<validation-message>必填字段不能为空</validation-message>

但是,您的标记似乎不包含具有指定文本的节点。

相反,您可以使用DOM节点状态获取输入元素的值。看看value属性是否满足您的需求。例如:

const requiredFields = Selector('input').withAttribute('required');
const requiredFieldsCount = await requiredFields.count;

for (let i = 0; i < requiredFieldsCount; i++) {
    const field = requiredFields.nth(i);
    const fieldValue = await field.value;
    if (!fieldValue)
        await t.typeText(field, "虚拟文本");
}

另请参阅:

获取元素状态

通过选择器枚举已识别的元素

英文:

The withText method filters existing DOM Nodes, which contain the specified text. For instance:

<validation-message>Required field cannot be left blank</validation-message>

However, your markup does not seem to contain nodes with the specified text.

Instead, you can obtain the value of your input elements by using the DOM Node State. See if the value property meets your requirements. For instance:

const requiredFields = Selector('input').withAttribute('required');
const requiredFieldsCount = await requiredFields.count;

for (let i = 0; i < requiredFieldsCount; i++) {
	const field = requiredFields.nth(i);
	const fieldValue = await field.value;
	if (!fieldValue)
		await t.typeText(field, "dummy text");
}

See also:

Obtain Element State

Enumerate Elements Identified by a Selector

huangapple
  • 本文由 发表于 2020年1月3日 20:02:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/59578299.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定