I am doing AngularJS testing using Protractor and using XPath makes the test quite slow. Also, it sometimes shows an error that it wasn't able to find the XPath, but works fine if I run it again.
Asked
Active
Viewed 772 times
2 Answers
1
If you are having problems with xpaths only working intermittently it could be due to you xpaths not being robust enough. http://scraping.pro/res/xpath-cheat/xpath_css_dom_recipes.pdf is a very helpful cheat sheet I use when working with xpaths.

Kristian
- 130
- 2
- 12
0
Yes, when you use protractor in a normal case you have better option then xpath.
You can select element's by models, bindings, etc. It's a proper way
Like
in mypage.po.js
file:
var MyPagePO = function () {
this.title = element(by.binding('some.title'));
this.emailInput = element(by.model('some.email'));
};
module.exports = MyPagePO;
And in mypage.spec.js
:
var MyPagePO = require('mypage.po.js');
describe('Login Page Tests.', function () {
var myPagePO = new MyPagePO();
beforeEach(function () {
//...
});
it('Some case.', function () {
expect(myPagePO.emailInput.getText()).toBe('some');
expect(myPagePO.title.getText()).toBe('some');
});
});
Take a look at this article, it's very helpful (and easy to understand).
And take a look about how to debug protractor's test

Community
- 1
- 1

S Panfilov
- 16,641
- 17
- 74
- 96
-
Thank you for the information. I have done this on simple pages of the Web App I am testing, but it becomes difficult when I move to the complex pages. I am newbie at testing, so, will reading more about how to extract elements in detail in the way mentioned will help? – Harman Mar 25 '16 at 09:22