英文:
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"中 - 请参见下文
我对没有文本"Required field cannot be left blank"的字段不感兴趣。form-control-warning
我需要这个,因为我必须在具有标签'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
I am not interested in such a filed where there is no text Required field cannot be left blank in. form-control-warning
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:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论