From ebc7bc5721f0aa0905a75cde9e1ae62ea89939d1 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Fri, 11 Aug 2023 11:32:49 +0100 Subject: [PATCH 1/2] Improvements --- check.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/check.py b/check.py index 9653c7e..d1d7933 100755 --- a/check.py +++ b/check.py @@ -1,6 +1,7 @@ #!/usr/bin/python3 import os +import re from datetime import date, datetime from playwright.sync_api import Playwright, Request, expect, sync_playwright @@ -57,14 +58,23 @@ def run(playwright: Playwright) -> None: # hr = HandleResponse() # page.on("requestfinished", hr.requestfinished) + re_month_name = re.compile(r"^([A-Z][a-z]+) (\d{4})$") + page.goto("https://www.eurotunnel.com/uk/") page.get_by_role("button", name="Accept All Cookies").click() + page.get_by_role("textbox", name="Outbound").click() - page.get_by_role("row", name="August 2023").get_by_role("cell").nth(1).click() + month_row = page.get_by_role("row", name=re_month_name) + month_and_year = month_row.inner_text() + if month_and_year == "August 2023": + month_row.get_by_role("cell").nth(1).click() + # page.get_by_role("row", name="August 2023").get_by_role("cell").nth(1).click() page.get_by_role("cell", name="29").click() + page.get_by_role("textbox", name="Return").click() page.get_by_role("row", name="September 2023").get_by_role("cell").nth(2).click() page.get_by_role("cell", name="6", exact=True).click() + page.get_by_role("button", name="Search and book").click() page.get_by_label("Enter your vehicle registration").fill("KE69HRR") page.get_by_role("button", name="Find").click() From 0e3a9d7ea2b03a4134c7c52ce2c9fc05d530c3bc Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Fri, 11 Aug 2023 11:35:32 +0100 Subject: [PATCH 2/2] Improvements --- check.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/check.py b/check.py index dc0fe7d..7f41650 100755 --- a/check.py +++ b/check.py @@ -55,8 +55,8 @@ def run(playwright: Playwright) -> None: context = browser.new_context() page = context.new_page() - # hr = HandleResponse() - # page.on("requestfinished", hr.requestfinished) + hr = HandleResponse() + page.on("requestfinished", hr.requestfinished) re_month_name = re.compile(r"^([A-Z][a-z]+) (\d{4})$") @@ -65,10 +65,11 @@ def run(playwright: Playwright) -> None: page.get_by_role("textbox", name="Outbound").click() month_row = page.get_by_role("row", name=re_month_name) - month_and_year = month_row.inner_text() + month_and_year = month_row.inner_text().strip() if month_and_year == "August 2023": month_row.get_by_role("cell").nth(1).click() - # page.get_by_role("row", name="August 2023").get_by_role("cell").nth(1).click() + else: + assert month_and_year == "September 2023" page.get_by_role("cell", name="29").click() page.get_by_role("textbox", name="Return").click()