×
☰ See All Chapters

What is the difference between xpath and css locator?

                 css

                        Xpath

It is faster

It is slower

text() function is not supported

text() function is supported

backward traversing is not supported

backward traversing is supported

groupIndex is not supported

groupIndex is supported

Why css locator is faster than xpath?

css locator is faster than xpath because css locator traverse in the html tree only in the downward direction, but xpath traverses in both upward and downward direction.

What is the difference between "/" and "//" in XPath?

Single Slash "/": Used in absolute path.

Double Slash "//": Used in relative path.

What is the priority order for using locators?

Below is the priority to use these locators

  1. id 

  2. name 

  3. linkText / partialLinkText 

  4. css 

  5. xpath 

Why using className and tagName locators is not recommended?

Because className and tagName might have been used only once in a page at the time of developing automation script, but it is not safe, developer may use same tags and class at any time. You will learn about all the locators in next chapters.

When do we use LinkText and partialLinkText locator?

LinkText  locator should be used when the text of the link is constant. partialLinkText locator should be used when certain part of the link text is getting changed every time the page is loaded. i.e. for partially dynamically changing text, we use partialLinkText locator.

When do we use id locator?

When the html source code has an id attribute, then we can use id locator. And what we pass as an argument to iid locator is the value of id attribute.

When do we use name locator?

When the html source code have name attribute, then we can use name locator. And what we pass as an argument to name locator is the value of name attribute.

How do you ensure the required page is displayed or not?

We can use following checkpoints to validate the required page is displayed or not.

  1. using title of the page 

  2. using URL of the page 

  3. using any unique element on the page 

We have both id and name attribute, which locator do we prefer?

We prefer id over name locator, because id is unique and name can be duplicated.

How do we handle dynamically changing objects on the webpage?

By using xpath with contains function when the attribute value or the text partially changes. If the text completely changes, we handle this scenario by using independent-dependent xpath concept.

 


All Chapters
Author