I'm using playwright to enter my email, navigate to a folder that automatically receives some emails every day. The body of the emails may contain a link to download a report or not, depending on whether there was production on that day.
The program enters email by email, clicks on the download link, and after downloading it goes to another email. However, when the first email without the download link is opened, the program stops working. The following error appears:
playwright._impl._api_types.TimeoutError: Timeout 30000.0ms exceeded while waiting for event "download"
=========================== logs ===========================
waiting for event "download"
============================================================
The code I'm using is the one below.
if page.locator("a", has_text="Download"): # Line that is supposed to be testing for the download link.
with page.expect_download() as download_info:
page.locator("a", has_text="Download").click()
download = download_info.value
path = download.path()
download.save_as(path=download.suggested_filename)
# Renaming and moving file
time.sleep(1)
check_file_downloaded()
rename_and_move_file()
elif page.locator('text=There are no data'): # Line that is supposed to be checking when there is no download link.
print('{} no production report.'.format(filename), end='')
continue
This code snippet is inside a for structure that should analyze all the emails that were received in the folder.
Any suggestions on how can I correctly test whether or not there will be the download link and if there is not the program, proceed to the analysis of the next email normally?