我使用的是 Node 版本 0.10.30。 在 Protractor 1.6.1 上,我能够转义 ng-show 中的单引号字符以返回值。例如:
element.all(by.css('[ng-if="user"]')).all(by.css('[ng-show="user.name === \'Jhonny\'"]').getText()
但是升级到 Protractor 1.8.0 和 2.0.0 后,字符转义不再起作用(升级后我回滚到 Protractor 1.6.1 并且它再次起作用)。然后我尝试另一个代码
element.all(by.css('[ng-if="user"]')).map(function(ele) {return ele;});
上面的代码使 elementExplorer 崩溃并出现以下错误:
(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
at Client.addListener (events.js:160:15)
at CommandRepl.evaluate_ (C:\Users\test\AppData\Roaming\npm\node_modules\protractor\lib\debugger\modes\commandRepl.js:111:15)
at CommandRepl.stepEval (C:\Users\test\AppData\Roaming\npm\node_modules\protractor\lib\debugger\modes\commandRepl.js:33:8)
at WdRepl.stepEval_ (C:\Users\test\AppData\Roaming\npm\node_modules\protractor\lib\debugger\clients\explorer.js:48:16)
at Interface.<anonymous> (repl.js:239:12)
at Interface.emit (events.js:95:17)
at Interface._onLine (readline.js:202:10)
at Interface._line (readline.js:531:8)
at Interface._ttyWrite (readline.js:760:14)
at ReadStream.onkeypress (readline.js:99:10)
我尝试使用 Protractor --elementExplorer 中的 Node 或目录运行 elementExplorer,两者都有相同的问题。还有人遇到过这种情况吗?
最佳答案
我在尝试使用 Protractor 中的元素资源管理器来转义 by.css 选择器上的撇号时遇到了同样的问题。 我的解决方案使用了双反斜杠:
element.all(by.css('[ng-if="user"]')).all(by.css('[ng-show="user.name === \\'Jhonny\\'"]').getText()
关于javascript - elementExplorer 字符转义在 Protractor 1.8.0 和 2.0.0 上回归?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29765882/