Created
April 24, 2024 07:42
-
-
Save shaunabandu/e0ccea16fe86da7d284ea72b553720ff to your computer and use it in GitHub Desktop.
Selenium xpath
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//webpage under test: https://www.freemalaysiatoday.com/category/nation/2024/04/24/jpj-fines-3-bus-drivers-for-making-tiktok-videos-calls-while-driving/ | |
//reference: https://www.guru99.com/xpath-selenium.html | |
//1. Basic Xpath | |
Xpath = "//summary[@class='list-none']"; | |
//2. Contains() | |
Xpath = "//input[contains(@type, 'emai')]"; | |
//3. AND or OR | |
XPath = "//*[@type='email' or @type='submit']"; | |
XPath = "//*[@type='email' and @name='email']"; | |
//4. Starts with | |
XPath = "//a[starts-with(@href, '/category')]"; | |
//5. Text | |
XPath = "//h2[text()='Most Viewed Last 2 Days']"; | |
//6. Ancestor | |
XPath = "//input[@type='email']//ancestor::div[@class='space-y-2']"; | |
//7. Child | |
XPath = "//div[@class='flex flex-col space-y-4']//child::a[2]"; | |
//8. Preceding | |
XPath = "//div[@class='flex flex-col space-y-4']//preceding::aside"; //Fails because aside comes before this div | |
Xpath = "//div[@class='flex flex-col space-y-4']//preceding::input"; //Passes because input comes after this div | |
//9. Following-sibling | |
XPath = "//div[@class='space-y-2']//following-sibling::button"; | |
//10. Parent | |
XPath = "//div[@class='space-y-2']//parent::form"; | |
//11. Descendant | |
XPath = "//main//descendant::form"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment