HomeSelenium

Selenium Locators – CSS Selectors have higher priority over XPath Expressions

Selenium Locators – CSS Selectors have higher priority over XPath Expressions

<<Previous Post                            << Complete Tutorial>>                              Next Post>>

In the previous article, I have explained that the XPath Expressions are powerful than all the other locators including CSS Selectors.

In this article, I am going to explain that despite XPath Expressions being powerful that CSS Selectors, the CSS Selectors have higher priority over XPath Expressions.

Let’s get started.

Selenium Locators – CSS Selectors have higher priority over XPath Expressions

The following are the different reasons for CSS Selectors having higher priority over XPath Expressions:

Reason#1 – When compared to XPath Expressions, CSS Selectors locate the UI elements faster. 

After reading the above reason, don’t think that the XPath Expressions are slow.

Both XPath Expressions and CSS Selectors faster enough in locating the UI elements on the web page, but CSS Selectors locate the elements faster than the XPath Expressions. And practically speaking, you will not be able to find that minute difference in speed between these two locators when you execute the Automation scripts in real-time.

Reason#2 – XPath Expressions are not the right choice when you are executing your Selenium Automation scripts having these locators on Internet Explorer Browser.

Every browser has its own engine. While Chrome and Firefox Browsers support the XPath Expressions without any problems, Internet Explorer won’t support the XPath Expressions so well.

In very rare cases, your Selenium Automation scripts having the XPath Expressions may fail on Internet Explorer and hence XPath Expressions are not reliable.

If your requirement says to test only on Chrome and Firefox, then you can give equal priority to XPath Expressions and CSS Selectors. But if your requirement has IE browser included, then give higher priority to CSS Selectors over XPath Expressions.

Hence in most of the companies, to avoid the above confusions, they give higher priority to CSS Selectors over XPath Expressions irrespective of their requirements and situations.

In the next article, I will explain the current status of FireBug and Firepath Firefox Add-ons.

Next Steps:

  • > To learn more about Selenium, continue to the next post (Click on Next Post link below)
  • > Check complete Selenium Tutorial Contents here (Click here)

Please leave your questions/comments/feedback below.

Happy Learning ?

About Me > Arun Motoori

On a mission to contribute to the Software Testing Community in all possible ways.

<<Previous Post                            << Complete Tutorial>>                              Next Post>>

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *

For FREE Testing Tutorials & Videos

X
Open chat
Contact Us on Whatsapp