In one of the previous article, we discussed on how an element can be identified using different locators. Two of the generic element locators are using xpath and cssSelector.
Using FirePath with firebug, we can evaluate the css/xpath for an element as well as generate CSS/ xpath for an element as shown in the below image.FirePath is helpful with following features.
Problem statement for this article:
- What is XPath and CSS Selectors?
- What are different tools to identify xpath or CSS for an element?
- Common interview questions around xpath and CSS?
- Common interview questions around xpath and CSS?
- Some excellent reference on the web explaining how to create Xpath/CSS Selectors?
What is XPath and CSS Selectors?
Xpath
|
CSS Selectors
|
|
Stands for?
|
Xpath stands for XML
Path language.
|
CSS stands for
Cascading style sheets
|
Definition?
|
XPath is used to
navigate through elements and attributes in an XML document.
|
CSS is a stylesheet
language that describes the presentation of an HTML (or XML) document.
|
XPath is syntax defining
parts of an XML document. Xpath uses path expressions to navigate in XML
documents
|
CSS selectors are
used to "find" (or select) HTML elements based on their element
name, id, class, attribute,etc
|
|
We can traverse
parent elements from child elements and vice versa using xpath.
|
CSS is native to
browsers while Xpath is not.
|
|
Syntax
|
driver.findElement(By.xpath(xpathExpression));
|
driver.findElement(By.cssSelector(CSSExpression));
|
Which locator
expression is more readable
|
In terms of
readability , CSS are more readable
|
|
Which locator is
comparably faster?
|
In various studies,
it is mentioned CSS to be comparably faster than Xpath
|
|
Which locator is the
best?
|
Since Id is believed
to be unique for an element and can help uniquely identify an element, it is
always best to use Id locator for object identification, if defined.
|
What are different tools to identify xpath or css Selector?
Using F12 or Inspect Element:
In most of the browsers, option to inspect element is available on pressing F12. Below image shows how to inspect elements in chrome browsers to inspect an element. Similarly we can inspect element in IE browser and firefox browser.
Using Firepath and Firebug:
- Generating xpath/css/sizzle for an element.
- Evaluating xpath/css/sizzle matches elements in the html.
- Viewing elements in the DOM tree structure.
Using Selenium IDE:
When we record script on the AUT, all the elements recorded are identified based on element locators in the page. The test script recorded can be exported to different languages e.g: c#, Java.
The script generated can be used in tests also.
What is difference between "/" and "//" in X-path?
"/" is used to create ‘absolute’ path expressions from document node
"//" is used to create relative path expressions
"//" is used to create relative path expressions
Some excellent Reference materials available on understanding Xpath and CSS Selector are:
- Comparison between xpath and CSS Selectors.
- Understand how to create xpath and CSS Selector
- http://www.w3schools.com/xsl/xpath_syntax.asp
- http://www.w3schools.com/cssref/css_selectors.asp
- https://www.simple-talk.com/dotnet/.net-framework/xpath,-css,-dom-and-selenium-the-rosetta-stone/ - The pdf documents for download in this article are excellent reference for creating xpath and CSS Selector.
thanks for shared wonderful information of giving best information.its more useful and more helpful. great doing keep sharing
ReplyDeleteBest CAT Coaching in Chennai
Thank you
DeleteThank you
ReplyDeleteThank you, You have spent good time I guess to write this kind of good articles, there is link for xpath, please do read it.relative XPATH in Selenium webdriver
ReplyDeleteSome us know all relating to the compelling medium you present powerful steps on this blog and therefore strongly encourage contribution from other ones on this subject while our own child is truly discovering a great deal. Have fun with the remaining portion of the year.
ReplyDeleteBig data training in Velachery
Big data training in Marathahalli
Big data training in btm
Big data training in Rajajinagar
Big data training in bangalore
thanks for shared wonderful information of giving best information.its more useful and more helpful. great doing keep sharing
ReplyDeleteSap Pp Training From India
Thanks for sharing such information.this is really helpful for me.you can also visit our blog
ReplyDeletejava training in chennai
java training in tambaram
aws training in chennai
aws training in tambaram
python training in chennai
python training in tambaram
selenium training in chennai
selenium training in tambaram
thanks for shared wonderful information of giving best information.its more useful and more helpful. great doing keep sharing
ReplyDeleteoracle training in chennai
oracle training in omr
oracle dba training in chennai
oracle dba training in omr
ccna training in chennai
ccna training in omr
seo training in chennai
seo training in omr
I genuinely appreciated understanding it. Sitting tight for some more incredible articles like this from you in the nearing days.
ReplyDeleteOnline training for big data
Big Data Hadoop Online Training
mmorpg oyunlar
ReplyDeleteİnstagram Takipçi Satın Al
TİKTOK JETON HİLESİ
tiktok jeton hilesi
antalya saç ekimi
referans kimliği nedir
İnstagram takipçi satın al
TAKİPÇİ SATIN AL
metin2 pvp serverlar
smm panel
ReplyDeleteSMM PANEL
https://isilanlariblog.com/
İNSTAGRAM TAKİPÇİ SATIN AL
hirdavatciburada.com
www.beyazesyateknikservisi.com.tr
Servis
tiktok jeton hilesi
Good content. You write beautiful things.
ReplyDeletemrbahis
vbet
hacklink
korsan taksi
sportsbet
mrbahis
sportsbet
taksi
hacklink
Good text Write good content success. Thank you
ReplyDeletepoker siteleri
betmatik
kralbet
bonus veren siteler
mobil ödeme bahis
slot siteleri
betpark
kibris bahis siteleri
çorum
ReplyDeleteantep
ısparta
hatay
mersin
JKXHT
https://saglamproxy.com
ReplyDeletemetin2 proxy
proxy satın al
knight online proxy
mobil proxy satın al
Z312JJ