kavitha
kavitha

Reputation: 117

how to find the span in protractor

i want to turn on the toggle button in protractor. below is the DOM

<input type="checkbox" id="UseRecipientList" ng-model="newProduct.useRecipientList" class="ng-pristine ng-untouched ng-valid">
<span>
::before
::after
</span>

if I identify the element by xpath, it is working fine. i have used, element(by.xpath("//input[@id='UseRecipientList']/following-sibling::span"));

if I want to go by ng-model, how to identify the span which comes after ng-model as above in protractor?

Upvotes: 0

Views: 341

Answers (2)

Madhan Raj
Madhan Raj

Reputation: 1442

Use css as below

const locator= element(by.css('input#UseRecipientList > span'));

So the above locator help you to get the span as below

locator.getText();

To inspect using model name.Try the below one.

var input = element(by.model('newProduct.useRecipientList'));

For more on ng-model refer https://www.protractortest.org/#/api?view=ProtractorBy.prototype.model

Hope it helps you!!

Upvotes: 2

Joaquin Casco
Joaquin Casco

Reputation: 734

Try with css locator

(by.css('[ng-model="newProduct.useRecipientList"] span'));

Upvotes: 0

Related Questions