Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

protractor: How to find element by exact text?

Tags:

protractor

testing applications encountered another problem. I need to click element by exact text, so i found a solution where I use cssContainingText and each,then if statment to comapre text and select certain element, but I think maybe is a better solution for that purpous?

Second questions: somewhere on stackoverflow I read that

element.click().then(){
dosomething;
});

will cause that 'dosomething;' will perform after click, I try this and it doesn't work, how to make that 'dosomething;' will perform after click;

like image 733
tealang Avatar asked Jun 25 '15 07:06

tealang


1 Answers

You can use by.xpath as a selector:

By exact text

element(by.xpath('.//*[.="text"]'))

By css class with exact text

element(by.xpath('.//*[.="text" and class="some-css-class"]'))

You can find a lot of xpath examples online. There's also a tester you can use.

like image 132
Delian Mitankin Avatar answered Sep 22 '22 01:09

Delian Mitankin