我是赛普拉斯的新手,这是我试图自动化/测试的场景: 因此,有一个按钮列表:一些按钮说“你好”,另一些按钮说“再见”。 如果一个按钮说“你好”,我希望它执行进一步的操作,如果它说“再见”,则执行其他一些操作。 使用开发工具检查按钮时:
html
<button class="Button__StyledButton-t5s0do-0 hZDZBR
OfferRequestTilestyles__StyledButton-sc-1dbu8p5-4 dRhsyx"
type="button">Hello</button>
当我将cypress选择器用于这些按钮时,我有:
javascript
cy.get(':nth-child(3) >
.OfferRequestTilestyles__PropertyDetailsWrapper-sc-1dbu8p5-3 >
.Button__StyledButton-t5s0do-0')
它继续进行,例如nth-child(3),nth-child(4)等,并且它可以是动态的,因此可以有10个按钮或20或50个按钮。
每个按钮也位于以下行中:
javascript
cy.get('.PageContainer-sc-26sn9a-0 > :nth-child(3)')
所以nth-child(3),nth-child(4)等。
因此,对于每个按钮,请检查按钮的文本,是否是“ hello”,是否是“ bye”。
如何完成此方案? 我在线阅读了解决方案并尝试了此方法,但这样做的正确方式看起来像这样:
javascript
cy.get('.OfferRequestTilestyles__PropertyDetailsWrapper-sc-1dbu8p5-
3')//get the page container
.find('Button__StyledButton-t5s0do-0')
.each(function(buttons){
var ourButtons=buttons.text()
cy.log("names:", ourButtons);
这是我得到的错误:
'Button__StyledButton-t5s0do-0', but never found it. Queried from
element: [ <div.OfferRequestTilestyles__AddressWrapper-sc-1dbu8p5-
2.OfferRequestTilestyles__PropertyDetailsWrapper-sc-1dbu8p5-
3.dpPJNW>, 24 more... ]```
Thanks for help!
答案 0 :(得分:0)
我成功使用以下方法循环浏览了按钮:
javascript
javascript
cy.get('.OfferRequestTilestyles__PropertyDetailsWrapper-sc-1dbu8p5-
3')//get the page container
.find('.Button__StyledButton-t5s0do-0')
.each(function(buttons){
var ourButtons=buttons.text()
cy.log("names:", ourButtons);
也接受Richard Matsen的回答,我错过了班级选择器。感谢您指出Richard!它帮助了我!