From f23afb756876e6fb21fefde831ffc6b53b36381c Mon Sep 17 00:00:00 2001 From: mardausdennis <71312763+mardausdennis@users.noreply.github.com> Date: Fri, 28 Aug 2026 11:00:44 +0200 Subject: [PATCH] match daily set activities by target instead of by position get_daily_set_elements returned everything after the first link in the panel. The panel also carries promotional links, so position hands one back as an activity. Clicking it leaves rewards.bing.com and every element captured before that goes stale, which is the exception reported in #45. Activities always point at a Bing search, so match on that. When nothing matches it returns nothing rather than falling back to position, since clicking a promo is worse than skipping the task and complete_bing_daily_set already reports the shortfall. --- src/element_selectors.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/element_selectors.py b/src/element_selectors.py index 0dc565c..6708372 100644 --- a/src/element_selectors.py +++ b/src/element_selectors.py @@ -157,8 +157,28 @@ class ElementSelectionUtils: return self._streaks_button(3) def get_daily_set_elements(self): - # The first link in the opened panel is the progress row, not an activity. - return self.get_sidebar_section().find_elements(By.TAG_NAME, "a")[1:] + """The daily set activities in the opened panel. + + Everything after the first link is not reliably an activity. The panel + also carries promotional links, a referral card and a Bing app promo have + both been observed sitting between the progress row and the activities. + Handing one of those back gets it clicked, which navigates away from + rewards.bing.com, and every element captured beforehand then goes stale. + + Activities always point at a Bing search, so match on that rather than on + position. If nothing matches, return nothing: clicking a promo is worse + than skipping the task, and the caller already reports the shortfall. + """ + activities = [] + + for link in self.get_sidebar_section().find_elements(By.TAG_NAME, "a"): + try: + if "bing.com/search" in (link.get_dom_attribute("href") or ""): + activities.append(link) + except StaleElementReferenceException: + continue + + return activities # ------------------------------------------------------------------ # explore on bing (absent in en-US, present in some other markets)