Eric Francis
Eric Francis

Reputation: 24287

How to set an attribute on an element with protractor?

I have this snippet that returns an ElementFinder

const elem = $('[formatcontrolname="startDate"]').$('input');

I want to set the attribute ng-reflect-model on this element.

Advice for doing this?

I've tried a few browser.executeScript commands, but I can't figure out how to leverage the variable elem.


Edit: I did not end up going this route. I was able to do what I needed using standard css selectors in protractor.

Upvotes: 0

Views: 4437

Answers (2)

Milan Kumar
Milan Kumar

Reputation: 439

I set the value of date attribute by following:

browser.driver.executeScript("document.getElementById('start-date').setAttribute('value','01/10/2017')");

Try this in your scenario, hope this might help.

Upvotes: 2

nilesh
nilesh

Reputation: 14287

You shouldn't be doing this, this is not what a normal user would do when they are interacting with your app. I'll try to answer the second part of your question

I've tried a few browser.executeScript commands, but I can't figure out how to leverage the variable elem.

var el = element(by.module('header'));
var tag = browser.executeScript('return arguments[0].tagName', el);

Copied straight from here

Upvotes: 2

Related Questions