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.
Download files
In this lesson, we'll learn how can we handle downloads and download files to our desired location. So here we'll visit the Unsplash website. You will find the link in the resources. So here you can see we have an image. We can go ahead and download it. If I click on this button, you will see it getting downloaded and saved into the downloads. So we'll go ahead and do the same with playwright. So let's go ahead and take in the URL and then we can go to the same. Then we'll go ahead and locate this button that is the download free button. You can see it is a link element with the download free text. So we can use the page dot get by role locator. The role is a link and it should contain the text download free. Now we can go ahead and store it as a button. Now we have to do one thing that is first of all we have to expect the download and tell it to play right. do that we can just use the with context manager that is with page expect download like this so playwright will expect a…
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.