fix: UttlesfordDistrictCouncil - house number prefix match in dropdown#1994
fix: UttlesfordDistrictCouncil - house number prefix match in dropdown#1994InertiaUK wants to merge 1 commit into
Conversation
…ch in dropdown select_by_visible_text fails when the dropdown text includes the street name (e.g. "72, Birchanger Lane") but only the house number is provided. Now tries exact match first, then iterates options matching by house number prefix.
📝 WalkthroughWalkthroughEnhanced address selection in Uttlesford District Council module by implementing a multi-step matching strategy: first attempts exact dropdown text match, then falls back to case-insensitive prefix matching, with explicit error handling for unmatched addresses. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Review rate limit: 0/1 reviews remaining, refill in 60 minutes.Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1994 +/- ##
=======================================
Coverage 86.67% 86.67%
=======================================
Files 9 9
Lines 1141 1141
=======================================
Hits 989 989
Misses 152 152 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@uk_bin_collection/uk_bin_collection/councils/UttlesfordDistrictCouncil.py`:
- Around line 68-71: The except block around
drop_down_values.select_by_visible_text(str(user_paon)) is too broad; import
selenium.common.exceptions.NoSuchElementException and change the except
Exception: to except NoSuchElementException: so only missing-option cases are
suppressed (other exceptions will propagate); update the imports at the top to
include NoSuchElementException and keep the matched=True logic as-is.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 127f449b-e450-401e-a4e7-3b9542a709eb
📒 Files selected for processing (1)
uk_bin_collection/uk_bin_collection/councils/UttlesfordDistrictCouncil.py
| try: | ||
| drop_down_values.select_by_visible_text(str(user_paon)) | ||
| matched = True | ||
| except Exception: |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# First, check the file exists and get its structure
head -100 uk_bin_collection/uk_bin_collection/councils/UttlesfordDistrictCouncil.pyRepository: robbrad/UKBinCollectionData
Length of output: 3726
🏁 Script executed:
# Check the imports section specifically
head -20 uk_bin_collection/uk_bin_collection/councils/UttlesfordDistrictCouncil.pyRepository: robbrad/UKBinCollectionData
Length of output: 741
🏁 Script executed:
# Look at lines around 68-71 to see the exact code
sed -n '60,85p' uk_bin_collection/uk_bin_collection/councils/UttlesfordDistrictCouncil.pyRepository: robbrad/UKBinCollectionData
Length of output: 1157
🏁 Script executed:
# Search for other uses of select_by_visible_text in the codebase to see how exceptions are handled
rg "select_by_visible_text" -A 3 -B 1Repository: robbrad/UKBinCollectionData
Length of output: 4605
🏁 Script executed:
# Search for any existing uses of NoSuchElementException in the codebase
rg "NoSuchElementException" .Repository: robbrad/UKBinCollectionData
Length of output: 2668
🏁 Script executed:
# Check if any files import from selenium.common.exceptions
rg "selenium.common.exceptions" .Repository: robbrad/UKBinCollectionData
Length of output: 1629
Narrow the except clause to NoSuchElementException.
The current except Exception: on line 71 catches all exceptions — including WebDriver errors, timeouts, and stale element references — and silently falls into the prefix loop instead of surfacing real failures. select_by_visible_text() raises selenium.common.exceptions.NoSuchElementException when no option matches; catching only that exception aligns with the project-wide pattern shown in AngusCouncil.py, ChichesterDistrictCouncil.py, SevenoaksDistrictCouncil.py, and others.
Add the import:
+from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import ByNarrow the except clause:
- except Exception:
+ except NoSuchElementException:🧰 Tools
🪛 Ruff (0.15.12)
[warning] 71-71: Do not catch blind exception: Exception
(BLE001)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@uk_bin_collection/uk_bin_collection/councils/UttlesfordDistrictCouncil.py`
around lines 68 - 71, The except block around
drop_down_values.select_by_visible_text(str(user_paon)) is too broad; import
selenium.common.exceptions.NoSuchElementException and change the except
Exception: to except NoSuchElementException: so only missing-option cases are
suppressed (other exceptions will propagate); update the imports at the top to
include NoSuchElementException and keep the matched=True logic as-is.
|
Included in May 2026 Release (PR #1992). Closing. |
select_by_visible_textfails when the dropdown text includes the street name (e.g. "72, Birchanger Lane") but only the house number is provided as paon.Now tries exact match first, then iterates options matching by house number prefix (handles "72," and "72 " patterns).
Testing: Verified with CM23 5QF / 72 — returns 12 bins.
Summary by CodeRabbit