量角器获得了出口的第二个元素
我有一个问题,我对量显影剂很新。
我需要通过文本获得一个元素,现在不可能更改UI构建以使用更好的选择器的方式。
带有文本摘要
的标签
const myElement = element(by.xpath("//span[text()='Summary']"));
因此,我现在拥有的是span
但是,屏幕上只有一个元素,但是,当有两个元素时,它会失败,但出现以下错误:
- 失败:元素不相互作用
可能是因为它正在尝试访问切换的第一个元素。 因此,我尝试在阅读时访问元素索引:
element(by.xpath("//span[text()='Summary']")[1]);
并收到以下错误:
失败:无效的定位器
我在某个地方读到值以1始于1而不是0的地方,因此我尝试了:
element(by.xpath("//span[text()='Summary']")[2]);
但是,我仍然遇到相同的错误:
失败:无效的定位器
可以找到这些第二个元素吗?
I have an issue and I'm quite new with protractor.
I need to get an element by its text, right now it is not possible to change how the UI is built to use better selectors.
So what I have right now is a span
tag with the text Summary
inside of it, to retrieve the element using XPath I do the following:
const myElement = element(by.xpath("//span[text()='Summary']"));
That works for the first occurrence when there's only one element on the screen, however, when there are two elements, it fails with the following error:
- Failed: element not interactable
Possibly because it is trying to access the first element which is toggled.
So I tried accessing the element index as I read around with:
element(by.xpath("//span[text()='Summary']")[1]);
And got the following error:
Failed: Invalid locator
I read somewhere that the values start on 1 and not on 0 so I tried with:
element(by.xpath("//span[text()='Summary']")[2]);
Yet, I'm still getting the same error:
Failed: Invalid locator
Is there a way I can get to these second element?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您使用列表切片时,就有更多的元素。因此,您可以尝试使用元素而不是元素
或
When you are using list slicing then there exist more then one elements. So you can try to use elements instead of element
OR
您可以尝试此XPATH,它有其他括号,您几乎已经到了。
(// span [text()='summary'])[2]
参考:
xpath查询以获取元素的nth实例
You can try this XPath, it has additional brackets, you have been almost there.
(//span[text()='Summary'])[2]
Reference:
XPath query to get nth instance of an element