protractor unknown error, removing attribute from

2019-02-19 17:49发布

问题:

Im new to protractor and trying to remove attribute from DOM but getting "unknown error", Im not sure what could be the problem

Im having a simple HTML with a custom directive.I am trying to remove that for my test cases to pass:

<input type="text" name="rptdate" input-date placeholder="DD-MM-YYYY" data-ng-model="newPatReports.reportDate" />

Commands I ran are:

browser.executeScript( 'document.getElementsByName("rptdate").removeAttribute("input-date")' );
browser.driver.findElement(protractor.By.name('rptdate')).removeAttr("input-date");
browser.executeScript('document.querySelector("input[name='rptdate']").removeAttribute("input-date");');

But none of them helped.

回答1:

Locate the element with Protractor and then pass the Web Element into the script:

var elm = element(by.name("rptdate"));

browser.executeScript('arguments[0].removeAttribute("input-date");', elm.getWebElement());