optimize search completion speed

This commit is contained in:
Carl Furtado
2026-08-20 10:29:34 -04:00
parent 2ffa64684c
commit f392d3e7a3
4 changed files with 36 additions and 22 deletions
+3
View File
@@ -61,6 +61,9 @@ class ElementSelectionUtils:
def get_bing_search_bar(self):
return self.driver.find_element(By.TAG_NAME, "textarea")
def get_clear_bing_search_query_button(self):
return self.driver.find_element(By.ID, "sw_clx")
def get_visual_search_button(self):
return self.driver.find_element(By.CSS_SELECTOR, "#sb_form > div.camera.icon")
+1 -1
View File
@@ -19,7 +19,7 @@ keyboard = mimic_typing.KeyboardUtils(driver)
rewards = rewards_tasks.RewardsTaskUtils(driver)
rewards.complete_all_tasks()
rewards.complete_required_searches()
input("Press Enter to exit...")
+16 -5
View File
@@ -218,6 +218,7 @@ def choose_target_in_element(x: int, y: int, height: int, width: int) -> Point:
class MouseUtils:
def __init__(self, driver: webdriver.Edge):
self.driver = driver
self.fallback_init_pos = (0, 0) # default fallback position if mouse position is not initialized
self.reinitialize()
def reinitialize(self):
@@ -225,14 +226,16 @@ class MouseUtils:
self.init_driver_with_cursor_visualization()
def init_driver_with_mouse_tracking(self):
js_tracker = """
window.cursorX = 0;
window.cursorY = 0;
document.addEventListener('mousemove', function(event) {
initial_pos = self.fallback_init_pos
js_tracker = f"""
window.cursorX = {initial_pos[0]};
window.cursorY = {initial_pos[1]};
document.addEventListener('mousemove', function(event) {{
console.log('Mouse moved to: ' + event.clientX + ', ' + event.clientY);
window.cursorX = event.clientX;
window.cursorY = event.clientY;
});
}});
"""
self.driver.execute_script(js_tracker)
@@ -265,6 +268,12 @@ class MouseUtils:
x = self.driver.execute_script("return window.cursorX;")
y = self.driver.execute_script("return window.cursorY;")
if (x, y) == (None, None):
self.reinitialize()
return self.get_current_mouse_position()
self.fallback_init_pos = (x, y)
return (x, y)
def move_mouse(self, move_time: float, path_function: Callable[[float], Point], visualize: bool=True):
@@ -281,6 +290,8 @@ class MouseUtils:
actions.pointer_action.move_to_location(point[0], point[1])
actions.perform()
self.fallback_init_pos = point
if visualize: self.driver.execute_script(f"window.moveVisualCursor({point[0]}, {point[1]});")
def move_to_element(self, element: WebElement, visualize: bool=True):
+16 -16
View File
@@ -110,8 +110,6 @@ class RewardsTaskUtils:
self.tab_utils.switch_to_other_tab()
self.mouse.reinitialize()
self.wait_for_then_click(self.elements.get_visual_search_button)
file_input = self.wait_for_element(self.elements.get_visual_search_file_input)
@@ -123,8 +121,6 @@ class RewardsTaskUtils:
self.tab_utils.switch_to_other_tab()
self.tab_utils.close_all_other_tabs()
self.mouse.reinitialize()
def complete_misc_cards(self):
self.switch_to_earn_page()
@@ -145,29 +141,33 @@ class RewardsTaskUtils:
self.tab_utils.close_all_other_tabs()
def complete_twenty_searches(self):
def complete_required_searches(self):
self.switch_to_earn_page()
self.wait_for_then_click(self.elements.get_points_breakdown_button)
self.wait_for_element(self.elements.get_close_button_on_points_breakdown) # make sure sidebar loads
points_earned, max_pts = self.elements.get_points_earned_from_searches_on_points_breakdown()
searches_needed = (max_pts - points_earned) // 5
self.driver.get("https://www.bing.com/")
search_bar = self.wait_for_element(self.elements.get_bing_search_bar)
self.wait_for_element(self.elements.get_bing_search_bar)
# search bar should be auto-focused
for query in llm_utils.get_related_search_queries(
llm_utils.get_random_noun(), num_queries=20
for i, query in enumerate(
llm_utils.get_related_search_queries(
llm_utils.get_random_noun(), num_queries=searches_needed
)
):
self.keyboard.send_keys(query+Keys.ENTER)
time.sleep(random.uniform(2, 3))
time.sleep(random.uniform(0.5, 1))
# clear search bar for next query
# the 't' can be any character, it just needs to be there to
# auto-focus the search bar so that the backspaces will work
self.keyboard.send_keys('t'+Keys.BACKSPACE*(len(query)+1))
self.move_to_and_click(self.elements.get_clear_bing_search_query_button())
self.driver.get("https://rewards.bing.com/")
self.mouse.reinitialize()
self.switch_to_earn_page()
self.wait_for_then_click(self.elements.get_points_breakdown_button)
@@ -195,5 +195,5 @@ class RewardsTaskUtils:
self.complete_explore_on_bing_tasks()
self.complete_visual_search()
self.complete_misc_cards()
self.complete_twenty_searches()
self.complete_required_searches()
self.claim_bonus_points()