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.
XPath functions
Now, we can select elements using XPath with their tag name and attributes. But what if we want to select elements based on their text. Let's say we would like to select this heading 1 element. To do that, we can use the text function. So let's just go ahead and use the page locator. start with the tag name that in this case is h1 so let's go ahead and do that and start with two slashes because this is a relative path and then inside of square brackets we can define functions and the function we are going to use is the text function why is it a function because we are going to call it using parentheses like this. What it will do is just give us the text inside of this h1 element and then we can match it using a equal sign and the thing which we want to match which will be let's say heading one and now I can go ahead and highlight the same. You can see our heading is highlighted. And you will notice that this text function is a exact match with what we are doing here. Unlike the get by…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
(Locked)
Playwright Python REPL8m 40s
-
(Locked)
Locator role8m 26s
-
(Locked)
Locators input field3m 39s
-
(Locked)
Locator text4m 6s
-
(Locked)
Locator alt text2m 22s
-
(Locked)
Locator title1m 56s
-
(Locked)
Locating with CSS selectors10m 7s
-
(Locked)
CSS selectors hierarchy8m 10s
-
(Locked)
CSS selectors pseudo classes9m
-
(Locked)
Locators XPath6m 5s
-
(Locked)
XPath functions7m 4s
-
(Locked)
Other locators10m 59s
-
(Locked)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-