I need a clarity between cssSelector and Relative Xpaths
.
Actually, we are having our Application UI in Angular js
in which there are only few locators like cssSelector and Xpaths but not id, names, classes and all etc.
So if we take absolute Xpaths
, its changing daily basis whenever developers update designs thats why i used cssSelector
but its also not seems to be feasible.
Can anyone let me know what would be the right approach if i use cssSelector
or Relative Xpaths
because i have to run my scripts in both browser IE all versions as well as Chrome latest version. which locator would be the best and how will i use them as if it changes on daily basis.
Asked
Active
Viewed 452 times
0

chriz
- 1,339
- 2
- 16
- 32
-
See this answer - http://stackoverflow.com/a/11778665/4720017. There are many questions/blogs debating about XPath vs CSS. – LittlePanda Apr 15 '15 at 11:04
-
possible duplicate of [Which is the best and fastest way to find the element using webdriver? By.XPath or By.ID or anything else? And why?](http://stackoverflow.com/questions/11777694/which-is-the-best-and-fastest-way-to-find-the-element-using-webdriver-by-xpath) – LittlePanda Apr 15 '15 at 11:04
-
I would advise using CSS ById wherever possible. However I have found that (in many Internet Explorer versions) that some CSS-based selectors simply will not work, which forces you into an XPath solution. Yes XPath tends to be slower, but if you're supporting I.E. XPath will likely always work. – Adam T Apr 15 '15 at 15:21
1 Answers
1
If you are testing on older IE versions, you will find that CSS selectors (even on newer versions) don't play very well with that browser. I would suggest building relative XPath selectors.

aholt
- 2,829
- 2
- 10
- 13
-
This advice is obsolete now. Modern IE optimizes for CSS and XPath is slow and flaky. – Peter M. - stands for Monica Jun 23 '17 at 17:03
-
Modern IE does. Re-read my advice again. I was talking about older IE versions. – aholt Jun 26 '17 at 13:14
-
We are in violent agreement here. For modern browsers, nobody should use XPath. And unless you have a VERY good reason, you should not optimize your code for old obsolete IE. So in general, **use CSS in most cases. ONLY use XPath if your target audience is old obsolete IE.** – Peter M. - stands for Monica Jun 26 '17 at 14:45
-
-
I am fighting quixotic fight against XPath. Suggesting to use CSS instead. – Peter M. - stands for Monica Jun 27 '17 at 16:18