XPath locator is one of the most quirky and one of the most precise locator. This disadvantage is clearly seen while running the tests under IE while Firefox works with xpath pretty well. This problem is related to internal browser features in particular to the libraries being used for elements location definition. But this is another story. The main thing is that tests which intensively use XPath work extremely slow under IE and this feature is the cause of huge variety of problems related to execution speed as well as quality of the tests itself especially during operations with dynamic content. For this reason CSS locators can be good alternative of XPath.
What can we do with CSS locators?
First of all,CSS locators also give the ability to describe object hierarchy. For instance, the XPath locator like:
First of all,
Xpath=//div//span/a
can be described via
css=div * span > a
From the sample above we may see analogy for XPath and
a) Character "/" meaning next level of
b) Character "//" meaning any object hierarchy level under current object corresponds to
Secondly, just like XPath, the
Xpath=//div[@id="some_id"]
can be described via
css=div[id=some_id]
Also there\'s abitity to check for partial attribute value matching. But
xpath=//div[contains(@title,"title")]
can be expressed via
css=div[@title~=title]
Both the locators can detect the element like
<div title="some multiword title" /> while the element like <div title="my_title" />
can\'t be detected by CSS locator from above.
AlsoCSS has simplified form for some attributes. For instance, the element having the id attribute like <div id=some_id /> can be located by the following CSS :
Also
css=div#some_id
In addition to that
xpath=//div[@class="myclass"]
has the following
css=div.myclass
Such features make
So, in some cases CSS locators are the analogs of XPath locators with one serious advantage: CSS works fast no matter what the browser we use.
Of course,
Hey informative blog..
ReplyDeleteIf you are looking for SELENIUM TRAINING IN CHENNAI here is the link
http://thecreatingexperts.com/selenium-training-in-chennai/
contact +91-08122241286
Iot Training in Bangalore
ReplyDeleteArtificial Intelligence Training in Bangalore
Machine Learning Training in Bangalore
Blockchain Training bangalore
Data Science Training in Bangalore
Big Data and Hadoop Training in bangalore
JavaScript is the most widely deployed language in the world
ReplyDeleteJavascript Interview Questions