Spread the love

Which is better Xpath or DOM?

Spread the love

DOM:
The Document Object Model (DOM) is a cross-
platform and language-independent convention for
representing and interacting with objects in HTML,
XHTML and XML documents. Objects in the DOM
tree may be addressed and manipulated by using
methods on the objects.
Ex: var element=document.getElementById(“intro”);
XPATH:
XPath, the XML Path Language, is a query language
for selecting nodes from an XML document. In
addition, XPath may be used to compute values
 (e.g., strings, numbers, or Boolean values) from the
content of an XML document.
Ex: //input[@id=”xxx”]

Table of Contents

 

They are complementary rather than competing. DOM provides a tree model of XML with low-level navigation capability (get first child, get next sibling, etc); XPath adds a much higher-level search and navigation capability

Note also that DOM is just one tree model for XML, and is very far from being the best: it’s the first and the worst, and it’s a shame that so many people still use it. In the Java world there are much better designs available such as JDOM and XOM.
But as starter I will remember DOM as the database and xpath is the SQL query.
Absolute Xpath :
1) start selection from the document node
2) Starts with //
3) e.g. “/html/body/p” matches all the paragraph elements
Google Search Box : /html/body/div[1]/div[2]/div[1]/div[1]/div[3]/div/div/div/form/fieldset[2]/div/div/div
Relative Xpath  :
1) start selection matching anywhere in the document
2) Starts with /
3) e.g. “//p” matches all the paragraph elements starts with p
Google Search Box : //*[@id=’gbqfqwb’]

READ  Object Repository Concept In Selenium

image credit:developer.chrome.com




Spread the love
READ  How to Resolve SocketException In Selenium for Internet Explorer and Chrome
Animesh Chatterjeehttps://techtravelhub.com/
I am the founder and owner of the blog - TechTravelHub.com, always love to share knowledge on test automation,tools,techniques and tips.I am a passionate coder of Java and VBScript.I also publish articles on Travel ideas and great honeymoon destinations.Apart from these, I am a gear-head,love to drive across India. I have shared lots of articles here on How to travel several parts of India.Customization of cars aka car modification is my another hobby.Get in touch with me on ani01104@gamil.com

Related Articles

Learn Object Repository in UFT in An Efficient and Fast Manner

Object Repository in UFT The post will cover the following topics Details...

Comments

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Recent Posts

Super Keyword in Java Simplified

Super Keyword Super Keyword in Java Simplified: Java defines a special...

Learn What Primary Tools For Test Automation

Primary Tools For Test Automation According to the Gartner report...

EDITOR PICKS


Spread the love