220 likes | 363 Views
(** Selenium Training: <br>https://www.edureka.co/testing-with-selenium-webdriver **)<br>This Edureka PPT on Xpath Tutorial talks about Xpath fundamentals and steps involved in writing a Xpath Script. It also gives a brief idea on types of Xpath, Xpath Functions along with an example.<br>Following topics are covered in this tutorial:<br><br>Introduction to Xpath<br>XML DocumentX<br>Xpath Syntax<br>Types of Xpath<br>Xpath Functions<br><br><br>Selenium playlist: https://goo.gl/NmuzXE
E N D
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Topics to be covered… 01 Introduction to Xpath 02 XML Document 03 Benefits of Xpath 04 Syntax & Terminology Types of Xpath 05 Xpath Functions 06 JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Introduction To Xpath Important strategy to locate elements in Selenium Xpath is a language to query XML documents It consists of a path expression along with some conditions XPath can be also defined as XML path JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
XML Document <bookstore> <book category= “cooking”> <title lang=“en”>Everyday Chinese</title> <author>K.S.Bose</author> <book> <book category= “children”> <title lang=“en”>Harry Potter</title> <author>J.K. Rowling</author> <book> JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
XML Tree bookstore book (category: cooking) book (category: children) title (Harry Potter) title (Everyday Chinese) author ( K.S Bose) author (J.K. Rowling)
XML Tree bookstore book (category: cooking) book (category: children) title (Harry Potter) title (Everyday Chinese) author ( K.S Bose) author (J.K. Rowling) Xpath = /bookstore/book[@category=‘children’]/author
Benefits of Xpath 1 Queries are compact 2 Queries are easily parsed 3 Queries are easy to read & type 4 Queries do not return repeated nodes 5 Syntax is simple for simple and common cases 6 You can uniquely identify any node in XML Document JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Syntax & Terminology of
Syntax and Terminology Select current node Select attributes Value of an attribute Xpath=/tagname[@Attribute=‘Value’] Tagname like input, div, img etc Attribute Name JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Types of Xpath Absolute Xpath Relative Xpath JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Types of Xpath Absolute Xpath It is the direct way to find the element, but the disadvantage of the absolute XPath is that if there are any changes made in the path of the element then that XPath gets failed. Relative Xpath Ex: /html/body/div[1]/section/div[1]/div JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Types of Xpath Absolute Xpath For, Relative Xpath the path starts from the middle of the HTML DOM structure. It starts with the double forward slash (//), which means it can search the element anywhere at the webpage Relative Xpath Ex: //input[@id=‘ap_email’] JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Xpath Functions <bookstore> <book category= “cooking”> <title lang=“en”>Everyday Chinese</title> <author>K.S.Bose</author> <book> <book category= “children”> <title lang=“en”>Harry Potter</title> <author>J.K. Rowling</author> <book> JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Xpath Functions contains( ) starts-with() text() JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Xpath Functions contains( ) contains() is a method used in XPath expression. It is used when the value of any attribute changes dynamically, for example, login information. Syntax: starts-with() Xpath=//*[contains(@type,'sub')] text() JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Xpath Functions contains( ) starts-with function finds the element whose attribute value changes on refresh or any operation on the webpage. starts-with() Syntax: Xpath=//label[starts-with(@id,’message')] text() JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Xpath Functions contains( ) In this expression, with text function, we find the element with exact text match as shown below. In our case, we find the element with text "UserID". starts-with() Syntax: Xpath=//td[text()=’UserID’] text() JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training