Skip to content

fix: NeathPortTalbotCouncil - user_agent and JS click for overlay bypass#1936

Open
InertiaUK wants to merge 1 commit intorobbrad:masterfrom
InertiaUK:fix/NeathPortTalbotCouncil
Open

fix: NeathPortTalbotCouncil - user_agent and JS click for overlay bypass#1936
InertiaUK wants to merge 1 commit intorobbrad:masterfrom
InertiaUK:fix/NeathPortTalbotCouncil

Conversation

@InertiaUK
Copy link
Copy Markdown

@InertiaUK InertiaUK commented Apr 9, 2026

The scraper was failing in headless Chrome because the default webdriver user agent gets challenged, and a modal overlay intercepts the submit click before the form can be posted.

Two small changes:

  • Pass a realistic desktop user agent to create_webdriver.
  • Use driver.execute_script('arguments[0].click()') on the submit button so the overlay doesn't eat the click.

Tested against a real address in Neath Port Talbot and the schedule now returns.

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Enhanced reliability of Neath Port Talbot Council address lookups through improved browser compatibility.
    • Strengthened cookie banner acceptance and form submission handling to reduce interaction failures.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 9, 2026

📝 Walkthrough

Walkthrough

Updated NeathPortTalbotCouncil WebDriver initialization to pass an explicit Chrome/138 Linux desktop user-agent string, and replaced three native Selenium clicks with JavaScript-invoked clicks, guarding the cookie banner click with error handling.

Changes

Cohort / File(s) Summary
WebDriver & Interaction Pattern Updates
uk_bin_collection/uk_bin_collection/councils/NeathPortTalbotCouncil.py
Changed WebDriver creation to pass explicit Chrome/138 Linux desktop user-agent instead of None. Replaced cookie banner click with JavaScript-invoked click wrapped in try/except error handling. Updated two subsequent UI interactions (findAddress and submit elements) to use JavaScript-invoked clicks via driver.execute_script("arguments[0].click();", element).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • Feat dec fixes #1765: Modifies create_webdriver implementation with single return point and window positioning, directly related to this PR's explicit user-agent parameter passing and WebDriver behavior changes.

Suggested reviewers

  • dp247

Poem

🐰 A user-agent card, a JavaScript spell,
Three clicks now dance where browser clicks fell,
With try/catch shields and errors ignored,
This council's form is deftly restored! 🎪

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: updating user_agent parameter and using JavaScript clicks to bypass overlay issues in NeathPortTalbotCouncil.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/NeathPortTalbotCouncil.py`:
- Around line 38-44: Replace the bare except in the cookie banner handling (the
WebDriverWait block that finds and clicks "ccc-notify-accept" in
NeathPortTalbotCouncil.py) so it only catches
selenium.common.exceptions.TimeoutException; import TimeoutException if needed
and let any other exceptions propagate (do not swallow them). Ensure the
try/except wraps the WebDriverWait + execute_script call and only handles the
timeout case, re-raising or not catching other Selenium/driver errors so real
failures surface.
🪄 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: 5479569a-8192-4f41-8d2d-2a5e0370d493

📥 Commits

Reviewing files that changed from the base of the PR and between 60bd3cc and 5970d6c.

📒 Files selected for processing (1)
  • uk_bin_collection/uk_bin_collection/councils/NeathPortTalbotCouncil.py

Comment on lines +38 to +44
try:
cookieAccept = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, "ccc-notify-accept"))
)
driver.execute_script("arguments[0].click();", cookieAccept)
except Exception:
pass
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify broad exception swallowing around cookie handling in this file.
rg -n -C3 'ccc-notify-accept|except Exception|except [A-Za-z_]+Exception|pass' \
  uk_bin_collection/uk_bin_collection/councils/NeathPortTalbotCouncil.py

Repository: robbrad/UKBinCollectionData

Length of output: 924


Catch only TimeoutException from the cookie banner click, not all exceptions.

Lines 43–44 swallow all exceptions with a bare except Exception: pass, which masks real Selenium/driver failures. The WebDriverWait timeout is the expected failure case; other errors should surface immediately to detect site or session changes.

🔧 Suggested change
+from selenium.common.exceptions import TimeoutException
...
-            except Exception:
-                pass
+            except TimeoutException:
+                # Cookie banner not shown; continue.
+                pass
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
try:
cookieAccept = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, "ccc-notify-accept"))
)
driver.execute_script("arguments[0].click();", cookieAccept)
except Exception:
pass
try:
cookieAccept = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, "ccc-notify-accept"))
)
driver.execute_script("arguments[0].click();", cookieAccept)
except TimeoutException:
# Cookie banner not shown; continue.
pass
🧰 Tools
🪛 Ruff (0.15.9)

[error] 43-44: try-except-pass detected, consider logging the exception

(S110)


[warning] 43-43: 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/NeathPortTalbotCouncil.py`
around lines 38 - 44, Replace the bare except in the cookie banner handling (the
WebDriverWait block that finds and clicks "ccc-notify-accept" in
NeathPortTalbotCouncil.py) so it only catches
selenium.common.exceptions.TimeoutException; import TimeoutException if needed
and let any other exceptions propagate (do not swallow them). Ensure the
try/except wraps the WebDriverWait + execute_script call and only handles the
timeout case, re-raising or not catching other Selenium/driver errors so real
failures surface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant