如何找到具有动态ID的元素?
我想找到此元素:
<tr class=" category-2 saleproductname " id="21" xpath="1">
<input class="check-box" id="BillInfo_4__isSelected" type="checkbox" value="true" xpath="1">
我正在尝试找到ID,但是ID是动态的,此特定项目可以具有ID =“ Billinfo_0__isselected,有时ID =” Billinfo_1__isseleded,我必须继续更改代码。有什么解决方案吗?这里只有ID = 21是唯一的,但也无法使用。我试图使用ID,因为该类很常见,并且也找到了其他元素。
I want to locate this element:
<tr class=" category-2 saleproductname " id="21" xpath="1">
<input class="check-box" id="BillInfo_4__isSelected" type="checkbox" value="true" xpath="1">
I am trying to locate the id, but the id is dynamic, this particular item can have id="BillInfo_0__isSelected, sometimes id="BillInfo_1__isSelected and I have to keep on changing them on code. Is there any solution to this? Here only the id = 21 is unique but unable to use this as well. I am trying to use id since the class is common and locates other elements too.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于
id =“ 21”
是唯一的,因此请查询并使用.find()
(在父母中会找到)访问输入,以防万一 如果
id =“ 21”
每个构建更改,则同一行是一个好主意
Since
id="21"
is unique, query for that and use.find()
(which will find within the parent) to access the inputIn case there's several inputs in the same row
If
id="21"
changes per build, it would be a good idea to add adata-cy
attribute您可以使用属性属性selectortor
[class^=“”]
[类$ =“”]
You can use the attribute selectors to find an element that:
[class^=""]
[class$=""]