![]() With XPath, you can find the page elements quickly and easily just like finding a file on your computer. Look familiar?Įvery file on the computer has its own path, so are the elements on a web page. ![]() To find the file named "author", the exact file path is \bookstore\book\author. If you are having trouble understanding how it works, think about how we go about finding a particular file on our computer. For our example, if we want to locate the element "author", the XPath would be like: XPath uses "/" to connect tags of different levels from the top to the bottom in order to specify the location of an element. An HTML element usually consists of a start tag and an end tag, with the content inserted in between. Text with angle brackets( ) is called a tag. Title, author, year, price are all level 3. HTML has different levels of elements, just like a tree structure. In this example, Level 1 is bookstore and level 2 is book. It can be easily understood as the "path" to find the target element within the HTML doc. XPath is the most commonly used language when people need to locate an element in an HTML doc. Everything you see on the webpage can be found within the HTML, such as an image, blocks of text, links, menus and etc. If you load a web page on a browser (Chrome, Firefox, etc), you can easily access the corresponding HTML doc by hitting the F12 key. Web pages are generally written in a language called HTML. It can help you find an element from the whole document precisely and quickly. XPath (XML Path Language) is a query language for selecting elements from an XML/HTML document. Matching XPath and Relative XPath (for loop) How to write an XPath (cheat sheet included)
0 Comments
Leave a Reply. |