Javascript 行书不起作用

Javascript 行书不起作用,javascript,protractor,angularjs-e2e,Javascript,Protractor,Angularjs E2e,我的测试中有一些JS脚本。我不明白为什么,但它现在停止工作了。 可能是在量角器更新(版本3.3.0)后发生的。 也许有人知道会发生什么 我的脚本: PsComponent.prototype.getHighlightedText = function () { return browser.executeScript_(function getSelectionText() { var text = ""; if (window.getSelection) {

我的测试中有一些JS脚本。我不明白为什么,但它现在停止工作了。 可能是在量角器更新(版本3.3.0)后发生的。 也许有人知道会发生什么

我的脚本:

    PsComponent.prototype.getHighlightedText = function () {
  return browser.executeScript_(function getSelectionText() {
    var text = "";
    if (window.getSelection) {
      text = window.getSelection().toString();
    } else if (document.selection && document.selection.type != "Control") {
      text = document.selection.createRange().text;
    }
    return text;
  });
};
结果:

nothing
- Failed: JavaScript error (WARNING: The server did not provide any stacktrace information)
以及:

结果:

nothing
- Failed: JavaScript error (WARNING: The server did not provide any stacktrace information)

没有直接回答这个问题,但下面是我们正在使用的类似功能(我想在任何浏览器测试自动化项目中都会自然而然地出现类似的情况):

使用示例:

expect(helpers.getCaretPosition(amountInput)).toEqual(1);
expect(helpers.getInputSelection(amountInput)).toEqual("-100.00");

非常感谢。对于我的方法来说,这是一个很好的选择,而且很有效。)但对于我来说,这是一种魔力,为什么我的方法现在不起作用…@太好了!我认为你们把这些函数复杂化了,我们基本上只是使用元素的
selectionStart
selectionEnd
,没有
窗口
文档
对象。谢谢