dcsimg
www.webdeveloper.com
Results 1 to 3 of 3

Thread: Which one is better locator: XPath or CSS-selector?

  1. #1
    Join Date
    Feb 2017
    Posts
    2

    Which one is better locator: XPath or CSS-selector?

    Hello everyone,

    I am new to this forum and completely new to the world of HTML, XML and related website technologies.

    During my learning of HTML, I learned about XPath and CSS (and CSS-selector). Both can be used to locate web elements on a webpage.

    Now out of profound confusion, I have no clue over XPath vs CSS-selector dilemma.

    Is there any performance advantage of one over another?

    Please provide your valuable suggestions highlighting the difference between these two technologies (XPath and css-selectors) in locating web elements.

  2. #2
    Join Date
    Feb 2017
    Posts
    1
    For starters there is no dramatic difference in performance between XPath and CSS. This is surprising since it is the main reason cited in favor of CSS. There may be other functionality or page structures that demonstrates this speed gap (e.g. more dense and complex pages), but it's not readily apparent -- and I'm skeptical that it would make a substantial impact (e.g. the order of magnitude difference demonstrated by Santi in a presentation at the SF Selenium Meetup back in 2011).

    Traversing the DOM in older browsers like Internet Explorer 8 does not work with CSS but is fine with XPath. And XPath can walk up the DOM (e.g. from child to parent), whereas CSS can only traverse down the DOM (e.g. from parent to child).

    Based on the data, XPath looks more favorable than it once was.

  3. #3
    Join Date
    Jun 2017
    Posts
    3
    Remember that not just execution is better with CSS locators, it's the similarity too that matters.

    We are trying on a multi program condition in which we utilize: IE, SAFARI, FIREFOX, CHROME.

    On IE the xpath never works OR it is SO moderate that it can't be overseen. So we utilize CSS any place we can. Sadly IE does not bolster numerous CSS rationales like, past thing, next thing, counters et cetera. However, that can be organized...

    You need to advise your Developers to give particular IDs To every single component you are utilizing. It will enormously accelerate your execution since you wont be expecting to much XPATH enchantment to achieve components.

    So conclusion:

    CSS is better with IE that is without a doubt. On different programs I didn't generally recognize any distinction.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center