Search code examples
javascripthtmltestingprotractorend-to-end

protractor unknown error, removing attribute from DOM


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.


Solution

  • 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());