如何从 selenium webdriver 获取 __reactInternalInstance (React 组件)

Moi*_*oiz 5 javascript mocha.js selenium-webdriver

我正在使用 selenium 编写集成测试web driver, Mocha and Chai,我想使用 Enzyme 来获取反应组件的元素。

当我这样做时driver.findElement(By.xpath('//div[@id="root"]/*[1]')),我得到了根元素,但我无法获取__reactInternalInstance根元素的 dom 属性中的内容。

我尝试这样做,getAttribute('_react instace id')但我没有得到这个。通过使用driver.executeScript()我得到了这个值,但它给了我maximum overstack错误,因为它是一个具有很多依赖项的大对象。

在此输入图像描述