量角器:元素当前不可交互,并且可能无法操纵

时间:2018-07-02 09:52:35

标签: javascript protractor

我试图在表单下定位元素以设置值(单击页面上的按钮后弹出),但是在弹出表单后无法找到该元素,出现以下错误:

Failed: invalid element state: Element is not currently interactable and may not be manipulated

HTML代码段如下:

<input class="form-control fc_short not-empty ng-pristine ng-not-empty ng-valid ng-valid-required ng-touched" ng-model="myNGModel" name="NGModel" ng-required="true" required="required" style="" type="text">

以下是已实现的代码:

it('should enter ABC value', function() {
    var elem = element.all(by.model('myNGModel')).first();
    var theStr = "ABC";
    browser.executeScript("arguments[0].scrollIntoView();", elem.getWebElement()).then(function() {
        elem.clear();
        elem.sendKeys(theStr);
        expect(elem.getAttribute('value')).toEqual(theStr);
    });
});

我错过任何重要的地方吗?我可以使用XPath如下找到该元素:

var elem = element(by.xpath('//*[@id="MyFormID"]/div/div/form/div[2]/div/div[2]/div/div[1]/div[3]/input'));

以下突出显示了其CSS路径:

html.ng-scope body.modal-open div.pushmenu.cbp-spmenu-push ui-view.ng-scope section#MainArea ng-include.ng-scope div#MyFormID.modal.modal-create.modal-2-col.ng-scope.in div.modal-dialog div.modal-content form.ng-pristine.ng-valid-required.ng-invalid.ng-invalid-required div.modal-body div.row div.col-md-8.col-md-pull-4 div.spanel div.top_panel div.form-group input.form-control.fc_short.not-empty.ng-pristine.ng-not-empty.ng-valid.ng-valid-required.ng-touched

1 个答案:

答案 0 :(得分:0)

clear方法块上引发了异常

    elem.clear();
    elem.sendKeys(theStr);
    expect(elem.getAttribute('value')).toEqual(theStr);

尽管该元素存在于页面上,但无法与之交互-输入将为read only,这就是引发此错误的原因。您可能需要等待一段时间才能使元素变得难以处理或明确地进行操作。

请阅读here中的说明。