赛普拉斯:是否可以从只有部分单词/s的动态下拉列表中选择一个项目?
我有一个下拉列表,该列表总是在可用的选项数量增加。我从选项中获得了“ recieptName”,但是,随后是不断变化的文本。例如:recieptname:“更改句子,包括单词和数字”。
我要做的是类似的事情:
cy.get('#RecieptName').select('RecieptName:');
但是,它找不到一个选项,因为它随后更改数字。是否可以根据部分选项找到该选项?
I have a dropdown list which is always increasing in the number of options available. I Have the 'RecieptName' from the option, however, it is followed by text that is constantly changing. eg: RecieptName: 'Changing sentence including words and numbers'.
What I am trying to do is something along the lines of:
cy.get('#RecieptName').select('RecieptName:');
However, it can't find an option with it as it is followed by changing the numbers. Is it possible to find the option based on a partial option?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要首先扫描选项,找到索引,然后
使用.contains()命令
使用正则
>
You would need to scan the options first, find it's index and select by number
Using .contains() command
Using a regex
Using selected prop
包含文本“ recieptName:”的选项可以通过添加
:contains()
来选择The option containing the the text "RecieptName:" can be selected by adding
:contains()
过滤器
将获得与特定选择器匹配的DOM元素。获得元素后,我们通过使用Invoke(text)
获得 recieptName 选项的确切文本,然后我们将相同的文本传递给select select < /code>命令,类似的内容:
您还可以使用
value
属性直接选择下拉列表,因为我可以看到值属性是唯一的,我想这将是最清洁的方法:filter
will get the DOM element that match a specific selector. Once we get the element, then we get the exact text of RecieptName option by using theinvoke(text)
and then we pass the same text to theselect
command, something like this:You can also use the
value
attribute to directly select the dropdown as I can see the value attributes are unique, I guess that would be the cleanest way to do this: