[英]Get dynamic id attribute value from an element
I need to check if a text value is displayed into a dynamic field after expand the row.我需要检查扩展行后文本值是否显示到动态字段中。
I paste part of the code where the info is displayed.我粘贴了显示信息的部分代码。 For the following code I have 10 rows in the screen with different IDs.
对于以下代码,我在屏幕中有 10 行具有不同的 ID。 Post a screenshot with code, to not loose the code formatting.
发布带有代码的屏幕截图,以免丢失代码格式。 Step by step of the text.
循序渐进的文字。
New question: How can I get the value attribute to compare it with the name of the file uploaded?新问题:如何获取value属性与上传的文件名进行比较? I try to use invoke(attr, value) but it does not work.
我尝试使用 invoke(attr, value) 但它不起作用。
<div class="bx--text-input__field-outer-wrapper">
<div class="bx--text-input__field-wrapper">
<input id="scenario-name-63add9a59b4cb45bc67d7bab"
type="text"
class="bx--text-input bx--form-item"
readonly=""
value="cypress1.png">
</div>
</div>
The issue is the id of the field that is dynamic.问题是动态字段的 ID。 I am able to list all the ids using the cypress code below.
我可以使用下面的柏树代码列出所有 ID。
//Expand all rows -** I know about multiple click but the idea is to use this block to do the loop**
cy.get('.bx--table-expand__svg')
.each(function($expand){
cy.wrap($expand).click()
})
**//Here I can list the id for each row, but I cant get the text for attribue value.**
cy.get('input[id*=scenario-]')
.each(function($scn,index,$scenarios){
cy.log($scn,index)
})
**//I try to use INVOKE, but it gets char by char e not the entire value.
//Here I can list the id for each row, but I cant get the text for attribue value. //在这里我可以列出每一行的id,但是我无法获取属性值的文本。
There's a jQuery function that will do this有一个 jQuery function 可以做到这一点
cy.get('input[id*=scenario-]')
.each(function($scn) {
const id = $scn.attr('id')
console.log('Exact id is: ', id)
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.