Reputation: 499
I need to check, using expect and Jasmine, if the text of the span in the button is "Vigente". How can I do it?
<button _ngcontent-hke-28="" class="btn btn-success disabled" tabindex="-1">
<span _ngcontent-hke-28="" class="glyphicon glyphicon-check">
</span> Vigente</button>
Can I use xpath like this:
/html/body/application/auth-container/layout/div/main-content/div/norma-cadastro/div/form/div[8]/div/button/text(Vigente)
Upvotes: 2
Views: 7450
Reputation: 1310
Can't say if it is correct or not.. But you can check it yourself in Chrome Dev tools. Just do inspect element on the element. And then right click on the element in HTML and click Copy. I would recommend using ID's or angular model if you can. XPaths change with changing HTML (unless you use ID's in XPath anyway) and then maintaining the tests becomes a task.
See the image.
Upvotes: 0
Reputation: 473873
First of all, the XPath expression you are asking about is not correct - the Vigente
part inside the parenthesis is not needed. Also, try not use absolute XPath expressions as the more levels in the path you have, the higher chances it'll break. And, XPaths are not recommended by the Protractor team.
Instead, I would locate the element by partial button text and check the presence of this element:
expect(element(by.partialButtonText("Vigente")).isPresent()).toBe(true);
Or, you can locate the element by, say, a CSS selector and get the text:
expect($("button.btn-success").getText()).toContain(Vigente);
The button.btn-success
CSS selector is though quite broad, see if you can improve it.
Upvotes: 3