使用打字稿和量角器[]定位shadowroot中的元素[

问题描述 投票:0回答:1

我正在尝试定位9-11阴影根内部的元素。常规定位器(例如xpath,css,id)无法定位。我可以使用Java中的JavascriptExecutor()来定位元素。但是这个过程非常繁琐。我也用打字稿在量角器框架上工作。我需要找到突出显示的元素。

非常感谢您的帮助![在此处输入图片描述] [1]

reactjs typescript protractor
1个回答
0
投票

我建议使用'by.react'组件,而不是使用自定义的javascript来查找元素,这使反应选择非常容易。

https://www.npmjs.com/package/protractor-react-selector

// with only component. If you don't provide any root element, it assume that root is set to '#root'
const myElement = element(by.react('MyComponent'));

// to fetch all elements matched with component, props and state, you can use protractor native 'all' method
const myElement = element.all(by.react('MyComponent'));

让我知道这是否对您有帮助:)

© www.soinside.com 2019 - 2024. All rights reserved.