From the course: Playwright Python and Pytest for Web Automation Testing: Master Modern Web Testing with Playwright and Pytest in Python

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Locators XPath

Locators XPath

In the previous lessons, we learned about the CSS selectors. In this one, we'll learn about the XPath. That is the XML querying language, which is specifically created to select web elements. Now XPath is a bit tougher, but provides more functionality than CSS selectors. So to use the same, we'll go ahead and try to select web elements based on their tag name and their attribute and its corresponding value. So let's say what we'd like to do is select the title of the website. Why? I'll just tell you that in a moment. Because with XPath, what we do is select things with path. What that means is that we can start from the very head of the element or the root of the document that is HTML itself and we use slashes to start and separate selectors or things. Let's say we'd like to start from the root. So we use a slash and type in the tag name of the root that is HTML. You can see it is selected. Then we need to go inside of the head. You can see it is selected. And then inside of the head,…

Contents