Following is the HTML where we have placeholder for name and email
<section slot="drawer" for="account" class="iron-selected">
<form class="form ng-pristine ng-valid">
<h4>CONTACT US</h4>
<p type="Name:"><input placeholder="Write your name here.."></p>
<p type="Email:"><input placeholder="Let us know how to contact you back..">
</p>
<button>Send Message</button>
</form>
</section>
Depending on what you exactly want to change.
Change the value of the attribute
Changing the value of an attribute can be done with "pure" javascript. This can be done with the browser.executeScript('your javascript code here');
, docs can be found here
Take in consideration that changing an attribute-value:
Change input
If you would like to send a value (so not changing the placeholder
-attribute) you can use the sendKeys()
-method. More info about how to use it look here
In your case you first need to identify the element you want to send the value to. It would be nice that the input
-element you need to send a value to has an unique selector. But with the code you gave you can solve it with this
// Because you can't select the input directly we can access it by it's parent
// `p` tag and then go to the input
element(by.css('p[type="Name:"] input')).sendKeys('my name is');
element(by.css('p[type="Email:"] input')).sendKeys('[email protected]');
At last you need to submit your form by clicking on the button
. Because your button
doesn't have an unique selector you can use the by.buttonText
method. This isn't a recommended method because you don't want to find elements based on their text. But for now u can do this
element(by.buttonText('Send Message'));
Your complete script will become
element(by.css('p[type="Name:"] input')).sendKeys('my name is');
element(by.css('p[type="Email:"] input')).sendKeys('[email protected]');
element(by.buttonText('Send Message'));
Hope this helps.