0% found this document useful (0 votes)
26 views9 pages

UDEMY - SK - XPath Tutorial From Basic To Advance Level

The document is a comprehensive guide on XPath, detailing its importance, writing methods, and advanced concepts such as relative XPath and its application to various web elements like SVG, Shadow DOM, and iFrames. It includes links to resources, test automation frameworks, and the author's profiles. The document serves as a tutorial for learning XPath from basic to advanced levels.

Uploaded by

abhimanyu thakur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views9 pages

UDEMY - SK - XPath Tutorial From Basic To Advance Level

The document is a comprehensive guide on XPath, detailing its importance, writing methods, and advanced concepts such as relative XPath and its application to various web elements like SVG, Shadow DOM, and iFrames. It includes links to resources, test automation frameworks, and the author's profiles. The document serves as a tutorial for learning XPath from basic to advanced levels.

Uploaded by

abhimanyu thakur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

====================================================

Tutor: Sanjay Kumar


Reference: UDEMY
Course: XPath Tutorial from basic to advance level
====================================================
1. Document prepared by
a. Rajat Verma
i. Github Profile: https://github.com/rajatt95

ii. Github Page: https://rajatt95.github.io

iii. LinkedIn: https://www.linkedin.com/in/rajatt95

iv. Topmate: https://topmate.io/rajatt95

v. Telegram: https://t.me/rajatt95

vi. Instagram: https://www.instagram.com/rajattvermaa95

vii. Youtube: https://www.youtube.com/@rajatt95


—------------------
2. Test Automation Frameworks available on Github
a. WEB

i. Selenium WebDriver + Java

ii. Cypress + (Javascript and Typescript)

iii. Playwright + (Javascript and Typescript)


b. MOBILE

i. Appium + Java
c. API

i. Rest Assured + Java

ii. Requests + Python

-------------------------------------------------------------------------------------------------------------------------------

1
—------------------
3. Documents:

a. Github repository: https://github.com/rajatt95/Documents

b. Google Drive:
https://drive.google.com/drive/folders/1tne9pZjgWvfrS0l9tVHs6k1jnQHpTLoA

4. Last worked on this Document:


a. Nov 26, 2022

============================================================================

-----------------------------------------
========1_Introduction & basic concepts of XPath==========
-----------------------------------------

1. XPath:
a. Each and every element on the web page has its own address
b. XPath is the address of an element

2. Importance of XPath:
a. As Important as the Tyres of a car
b. Scripts should not break
—------------------
3. How to write XPath:
a. Absolute: Single forward-slash (/)
i. Coming to Element step-by-step
ii. This makes XPath performance very slow
iii. Starts from HTML tag
b. Relative: Double forward-slash (//)
i. Directly jump to the element
c. XPath syntax functions
i. /tagName
ii. //tagName[@attribute=’attributeValue’]
iii. AND, OR functions
iv. text(), normalize-space(), .
v. Index, position.last,etc.
vi. Relative XPath using axes
vii. Relative XPath without using axes

-------------------------------------------------------------------------------------------------------------------------------

2
—------------------

4. What is the right platform to write and verify XPath:


a. Chrome DevTools
b. Console $x
c. Using SelectorsHub
—------------------

5. Get all the links on the page:


a. ChromeDevTools
i. It actually matches the String as well
ii. Therefore, it gives the wrong count

1.
iii. Search: Not only for XPath
1. Find By String, Selector, or XPath
b. SelectorsHub

i.
ii. SVG elements, Frames, Shadow DOM
iii. Intelli sense

—------------------

-------------------------------------------------------------------------------------------------------------------------------

3
-----------------------------------------
===2_Writing normal XPath and relative XPath with advanced concepts=====
-----------------------------------------

1. Relative XPath:
a. //tagName[@attribute=’attributeValue’]
b. //tagName[contains(@attribute,’subStringOfattributeValue’)]
c. //tagName[text()=’value’]
d. //tagName[contains(text(),’value’)]
e. //tagName[normalize-space()=’value’]
i. normalize-space() -> removes the unnecessary spaces
f. //a[@title='Platform' and @class='dropdown-toggle']
g. //a[@title='Platform' or @class='dropdown-toggle']

—------------------
NOTE:
1. text() -> not supported by cssSelector
—------------------

1. Relative XPath using Axes:


a. Following
b. Preceding
c. Ancestor - Grandparents
d. Descendant
2. https://testproject.io/
a. XPath for Forum w.r.t. Blog -
i. //a[@title='Blog']/ancestor::ul//a[@title='Forum']
1. XPath for Blog
2. Go to common Parent
3. Traverse to Forum
b. XPath for Platform w.r.t. Blog -
i. //a[@title='Blog']/ancestor::ul//a[@title='Platform']
c. XPath for SignUp w.r.t. Login-
i. //a[normalize-space()='Login']/ancestor::ul//a[contains(.,'Free Sign
Up')]

—------------------

-------------------------------------------------------------------------------------------------------------------------------

4
-----------------------------------------
========3_XPath for special types of Elements==========
-----------------------------------------

1. SVG elements:
a. These are the vector elements
b. Used to provide the icons over the web page
c. https://testproject.io/

d.
e. //a[@href='https://twitter.com/TestProject_io']//*[local-name()='svg']
f. SVG element : //*[local-name()=’svg’]
g. Path element : //*[name()=’path’]
—------------------

2. Shadow DOM elements:


a. XPath does not support Shadow DOM or vice-versa
b. It is DOM inside DOM
c. Starts with #shadow-root

d.
e. Shadow DOM
i. Open -> we can access DOM inside it
ii. Close -> we can not access -> SECURITY
—------------------

-------------------------------------------------------------------------------------------------------------------------------

5
—------------------
3. iFrames:

a.
—------------------
4. Dynamic elements (which disappear from DOM):
a. Right-click -> Selectors Hub -> Copy Relative XPath

i.

—------------------

-------------------------------------------------------------------------------------------------------------------------------

6
—------------------
b. Turn on Debugger

i.
-----------------------------------------
========4_Tips and tricks==========
-----------------------------------------

1.

—------------------

-------------------------------------------------------------------------------------------------------------------------------

7
-----------------------------------------
========5_Locator Challenge==========
-----------------------------------------

1. Get text using XPath:

a.
------------------------------------------

1.
2. //ul[@class=’footer__socials’]//a/@href -> Gives all the links

—----------------

-------------------------------------------------------------------------------------------------------------------------------

8
=======================================================================

1. Documents

a. Github repository: https://github.com/rajatt95/Documents

b. Google Drive:
https://drive.google.com/drive/folders/1tne9pZjgWvfrS0l9tVHs6k1jnQHpTLoA

2. Learnings from Tutor (Code Repository)


a. This course:
i. https://github.com/stars/rajatt95/lists/udemy-oc-selenium
b. Other course(s):
i. https://github.com/stars/rajatt95/lists/udemy-omprakash-chavan

3. To connect

a.
=======================================================================

=======================================================================

-------------------------------------------------------------------------------------------------------------------------------

You might also like