From b1dbb05066c9cd93de07be79f082f484dd7e1be7 Mon Sep 17 00:00:00 2001 From: Adam Christie Date: Fri, 10 Jan 2025 09:44:59 +0000 Subject: [PATCH 1/2] fix: Update Rushcliffe Borough Council input elements and flow Some controls had changed their IDs and the transition to the final panel wasn't being picked up anymore. --- .../councils/RushcliffeBoroughCouncil.py | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/uk_bin_collection/uk_bin_collection/councils/RushcliffeBoroughCouncil.py b/uk_bin_collection/uk_bin_collection/councils/RushcliffeBoroughCouncil.py index 579cb59675..2bd9321a18 100644 --- a/uk_bin_collection/uk_bin_collection/councils/RushcliffeBoroughCouncil.py +++ b/uk_bin_collection/uk_bin_collection/councils/RushcliffeBoroughCouncil.py @@ -7,6 +7,7 @@ from uk_bin_collection.uk_bin_collection.common import * from uk_bin_collection.uk_bin_collection.get_bin_data import AbstractGetBinDataClass +import string # import the wonderful Beautiful Soup and the URL grabber class CouncilClass(AbstractGetBinDataClass): @@ -37,42 +38,57 @@ def parse_data(self, page: str, **kwargs) -> dict: # Populate postcode field inputElement_postcode = driver.find_element( By.ID, - "ctl00_ContentPlaceHolder1_FF3518TB", + "FF3518-text", ) inputElement_postcode.send_keys(user_postcode) # Click search button driver.find_element( By.ID, - "ctl00_ContentPlaceHolder1_FF3518BTN", + "FF3518-find", ).click() # Wait for the 'Select address' dropdown to appear and select option matching UPRN dropdown = WebDriverWait(driver, 10).until( EC.presence_of_element_located( - (By.ID, "ctl00_ContentPlaceHolder1_FF3518DDL") + (By.ID, "FF3518-list") ) ) # Create a 'Select' for it, then select the matching URPN option dropdownSelect = Select(dropdown) - dropdownSelect.select_by_value("U" + user_uprn) + found_uprn = False + for o in dropdownSelect.options: + ov = o.get_dom_attribute("value") + if "U" + user_uprn in ov: + dropdownSelect.select_by_value(ov) + found_uprn = True + break + + if not found_uprn: + raise Exception("could not find UPRN " + user_uprn + " in list") # Wait for the submit button to appear, then click it to get the collection dates submit = WebDriverWait(driver, 10).until( EC.presence_of_element_located( - (By.ID, "ctl00_ContentPlaceHolder1_btnSubmit") + (By.ID, "submit-button") + ) + ).click() + + # Wait for the confirmation panel to appear + conf_div = WebDriverWait(driver, 10).until( + EC.presence_of_element_located( + (By.CLASS_NAME, "ss_confPanel") ) ) - submit.click() soup = BeautifulSoup(driver.page_source, features="html.parser") - bins_text = soup.find("div", id="ctl00_ContentPlaceHolder1_pnlConfirmation") + bins_text = soup.find("div", id="body-content") if bins_text: results = re.findall( - "Your (.*?) bin will next be collected on (\d\d?\/\d\d?\/\d{4})", - bins_text.find("div", {"class": "ss_confPanel"}).get_text(), + r"Your (.*?) bin will next be collected on (\d\d?\/\d\d?\/\d{4})", + bins_text.get_text(), ) if results: for result in results: From a86253d9cac4bc6a445cf5891dc5066da91dea1b Mon Sep 17 00:00:00 2001 From: Adam Christie Date: Fri, 10 Jan 2025 12:05:58 +0000 Subject: [PATCH 2/2] fix: Use visibility of list rather than existence Remove race condition for address list. --- .../councils/RushcliffeBoroughCouncil.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/uk_bin_collection/uk_bin_collection/councils/RushcliffeBoroughCouncil.py b/uk_bin_collection/uk_bin_collection/councils/RushcliffeBoroughCouncil.py index 2bd9321a18..79437331e7 100644 --- a/uk_bin_collection/uk_bin_collection/councils/RushcliffeBoroughCouncil.py +++ b/uk_bin_collection/uk_bin_collection/councils/RushcliffeBoroughCouncil.py @@ -48,12 +48,13 @@ def parse_data(self, page: str, **kwargs) -> dict: "FF3518-find", ).click() - # Wait for the 'Select address' dropdown to appear and select option matching UPRN + # Wait for the 'Select address' dropdown to be visible and select option matching UPRN dropdown = WebDriverWait(driver, 10).until( - EC.presence_of_element_located( + EC.visibility_of_element_located( (By.ID, "FF3518-list") ) ) + # Create a 'Select' for it, then select the matching URPN option dropdownSelect = Select(dropdown) found_uprn = False @@ -67,11 +68,10 @@ def parse_data(self, page: str, **kwargs) -> dict: if not found_uprn: raise Exception("could not find UPRN " + user_uprn + " in list") - # Wait for the submit button to appear, then click it to get the collection dates - submit = WebDriverWait(driver, 10).until( - EC.presence_of_element_located( - (By.ID, "submit-button") - ) + # Click submit button + driver.find_element( + By.ID, + "submit-button", ).click() # Wait for the confirmation panel to appear