From 68b5de32d6bef3677dac47cfe0d6feebdc4ee2e5 Mon Sep 17 00:00:00 2001 From: augustin64 Date: Fri, 12 Apr 2024 23:28:46 +0200 Subject: [PATCH 1/8] fix de la popup "explorer le programme" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit peu satisfaisant, consiste juste à fermer la popup à chaque fois qu'elle apparaît sans s'en débarrasser définitivement --- V6.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/V6.py b/V6.py index 7bb6d2d..dab83fc 100755 --- a/V6.py +++ b/V6.py @@ -9,6 +9,8 @@ from modules.db import add_to_database from modules.driver_tools import * from modules.error import * +from selenium.common.exceptions import ElementClickInterceptedException + # create a webdriver def create_driver(mobile=False): @@ -243,7 +245,15 @@ def all_cards(): custom_sleep(1.5) driver.execute_script("arguments[0].scrollIntoView();", card_list[i]) custom_sleep(1.5) - card_list[i].click() + try: + card_list[i].click() + except ElementClickInterceptedException: # Popup "Explorer le programme" + debug("Popup 'Explorer le programme' reçue") + rewards_box = driver.find_element_by_css_selector('[aria-label="Boîte de dialogue Récompenses"]') + close_button = driver.find_element_by_css_selector('[aria-label="Fermer"]') + close_button.click() + custom_sleep(1.5) + card_list[i].click() if len(driver.window_handles) > 1: driver.switch_to.window(driver.window_handles[1]) From d7d2f49a3f75acce181fb64646a05e48a843956b Mon Sep 17 00:00:00 2001 From: augustin64 Date: Fri, 12 Apr 2024 23:46:26 +0200 Subject: [PATCH 2/8] =?UTF-8?q?pas=20la=20seule=20occurrence=20=C3=A9videm?= =?UTF-8?q?ment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- V6.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/V6.py b/V6.py index dab83fc..3d9b7d5 100755 --- a/V6.py +++ b/V6.py @@ -198,6 +198,14 @@ def do_poll(): # Find each playable card and tries to click on it to earn points def all_cards(): driver = config.WebDriver.driver + + def popup_exploration(): + debug("Popup 'Explorer le programme' reçue") + rewards_box = driver.find_element_by_css_selector('[aria-label="Boîte de dialogue Récompenses"]') + close_button = driver.find_element_by_css_selector('[aria-label="Fermer"]') + close_button.click() + custom_sleep(1.5) + driver.get("https://rewards.bing.com") wait_until_visible(By.CLASS_NAME, "c-card-content", 10, driver) @@ -248,11 +256,7 @@ def all_cards(): try: card_list[i].click() except ElementClickInterceptedException: # Popup "Explorer le programme" - debug("Popup 'Explorer le programme' reçue") - rewards_box = driver.find_element_by_css_selector('[aria-label="Boîte de dialogue Récompenses"]') - close_button = driver.find_element_by_css_selector('[aria-label="Fermer"]') - close_button.click() - custom_sleep(1.5) + popup_exploration() card_list[i].click() if len(driver.window_handles) > 1: @@ -266,7 +270,12 @@ def all_cards(): if "mee-icon-AddMedium" in card_list[i].get_attribute("innerHTML"): driver.execute_script("arguments[0].scrollIntoView();", card_list[i]) - card_list[i].click() + try: + card_list[i].click() + except ElementClickInterceptedException: # Popup "Explorer le programme" + popup_exploration() + card_list[i].click() + driver.switch_to.window(driver.window_handles[1]) custom_sleep(10) log_error(f"Card {i} Can't be completed. Why MS ?") From fcb40537dc1b9c6dc9af8d0bb8e77a8bf88b04cf Mon Sep 17 00:00:00 2001 From: augustin64 Date: Sat, 13 Apr 2024 10:06:21 +0200 Subject: [PATCH 3/8] Use newer method --- V6.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/V6.py b/V6.py index 3d9b7d5..eaad4a2 100755 --- a/V6.py +++ b/V6.py @@ -201,8 +201,8 @@ def all_cards(): def popup_exploration(): debug("Popup 'Explorer le programme' reçue") - rewards_box = driver.find_element_by_css_selector('[aria-label="Boîte de dialogue Récompenses"]') - close_button = driver.find_element_by_css_selector('[aria-label="Fermer"]') + rewards_box = driver.find_element(By.CSS_SELECTOR, '[aria-label="Boîte de dialogue Récompenses"]') + close_button = rewards_box.find_element(By.CSS_SELECTOR, '[aria-label="Fermer"]') close_button.click() custom_sleep(1.5) From ae023688a4e8dbd916e0c732a36099a73cc3f70e Mon Sep 17 00:00:00 2001 From: augustin64 Date: Sat, 13 Apr 2024 10:15:26 +0200 Subject: [PATCH 4/8] welcome-tour: URL check --- V6.py | 85 +++++++++++++++++++++++++++++++---------------------------- 1 file changed, 44 insertions(+), 41 deletions(-) diff --git a/V6.py b/V6.py index eaad4a2..e13c214 100755 --- a/V6.py +++ b/V6.py @@ -199,12 +199,16 @@ def do_poll(): def all_cards(): driver = config.WebDriver.driver - def popup_exploration(): - debug("Popup 'Explorer le programme' reçue") + def check_welcome_tour() -> bool: + if "rewards.bing.com/welcometour" not in driver.current_url: + return False + + info("Popup 'Explorer le programme' reçue") rewards_box = driver.find_element(By.CSS_SELECTOR, '[aria-label="Boîte de dialogue Récompenses"]') close_button = rewards_box.find_element(By.CSS_SELECTOR, '[aria-label="Fermer"]') close_button.click() custom_sleep(1.5) + return True driver.get("https://rewards.bing.com") wait_until_visible(By.CLASS_NAME, "c-card-content", 10, driver) @@ -249,48 +253,47 @@ def all_cards(): if i == len(card_list) and i > 15: checked = False - if checked: - custom_sleep(1.5) + if not checked: + continue + + custom_sleep(1.5) + driver.execute_script("arguments[0].scrollIntoView();", card_list[i]) + custom_sleep(1.5) + check_welcome_tour() + card_list[i].click() + + if len(driver.window_handles) > 1: + driver.switch_to.window(driver.window_handles[1]) + try_play(driver.title) + close_tab(driver.window_handles[1]) + + try: + driver.refresh() + card_list = driver.find_elements(By.CLASS_NAME, "c-card-content") + + if "mee-icon-AddMedium" not in card_list[i].get_attribute("innerHTML"): + continue + driver.execute_script("arguments[0].scrollIntoView();", card_list[i]) - custom_sleep(1.5) + check_welcome_tour() + card_list[i].click() + + driver.switch_to.window(driver.window_handles[1]) + custom_sleep(10) + log_error(f"Card {i} Can't be completed. Why MS ?") try: - card_list[i].click() - except ElementClickInterceptedException: # Popup "Explorer le programme" - popup_exploration() - card_list[i].click() + try_play(driver.title) # go back to the main page + try: + close_tab(driver.window_handles[1]) + except Exception as e: + debug(e) + except Exception as e: + debug(e) + driver.get("https://rewards.bing.com") - if len(driver.window_handles) > 1: - driver.switch_to.window(driver.window_handles[1]) - try_play(driver.title) - close_tab(driver.window_handles[1]) - - try: - driver.refresh() - card_list = driver.find_elements(By.CLASS_NAME, "c-card-content") - - if "mee-icon-AddMedium" in card_list[i].get_attribute("innerHTML"): - driver.execute_script("arguments[0].scrollIntoView();", card_list[i]) - try: - card_list[i].click() - except ElementClickInterceptedException: # Popup "Explorer le programme" - popup_exploration() - card_list[i].click() - - driver.switch_to.window(driver.window_handles[1]) - custom_sleep(10) - log_error(f"Card {i} Can't be completed. Why MS ?") - try: - try_play(driver.title) # go back to the main page - try: - close_tab(driver.window_handles[1]) - except Exception as e: - debug(e) - except Exception as e: - debug(e) - driver.get("https://rewards.bing.com") - except Exception as err: - log_error(err) - custom_sleep(3) + except Exception as err: + log_error(err) + custom_sleep(3) def promo(): From 1ea1ff776e3130e2114b990746a0a5943ba34c92 Mon Sep 17 00:00:00 2001 From: augustin64 Date: Sat, 13 Apr 2024 10:26:21 +0200 Subject: [PATCH 5/8] wait until visible --- V6.py | 1 + 1 file changed, 1 insertion(+) diff --git a/V6.py b/V6.py index e13c214..3727e3f 100755 --- a/V6.py +++ b/V6.py @@ -204,6 +204,7 @@ def all_cards(): return False info("Popup 'Explorer le programme' reçue") + wait_until_visible(By.CSS_SELECTOR, '[aria-label="Boîte de dialogue Récompenses"]', timeout=10, browser=driver) rewards_box = driver.find_element(By.CSS_SELECTOR, '[aria-label="Boîte de dialogue Récompenses"]') close_button = rewards_box.find_element(By.CSS_SELECTOR, '[aria-label="Fermer"]') close_button.click() From feb7834d1f3cd2ce57eee0aeb7dd4a4593cc5455 Mon Sep 17 00:00:00 2001 From: augustin64 Date: Sat, 13 Apr 2024 10:26:53 +0200 Subject: [PATCH 6/8] sleep a bit --- V6.py | 1 + 1 file changed, 1 insertion(+) diff --git a/V6.py b/V6.py index 3727e3f..43ea44e 100755 --- a/V6.py +++ b/V6.py @@ -205,6 +205,7 @@ def all_cards(): info("Popup 'Explorer le programme' reçue") wait_until_visible(By.CSS_SELECTOR, '[aria-label="Boîte de dialogue Récompenses"]', timeout=10, browser=driver) + custom_sleep(1.5) rewards_box = driver.find_element(By.CSS_SELECTOR, '[aria-label="Boîte de dialogue Récompenses"]') close_button = rewards_box.find_element(By.CSS_SELECTOR, '[aria-label="Fermer"]') close_button.click() From 19cf77c6bd1e9902cbf0394256a722b6b666f46a Mon Sep 17 00:00:00 2001 From: augustin64 Date: Sat, 13 Apr 2024 10:57:32 +0200 Subject: [PATCH 7/8] make an actual choice --- V6.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/V6.py b/V6.py index 43ea44e..3b0c65c 100755 --- a/V6.py +++ b/V6.py @@ -9,7 +9,7 @@ from modules.db import add_to_database from modules.driver_tools import * from modules.error import * -from selenium.common.exceptions import ElementClickInterceptedException +import random # create a webdriver @@ -204,11 +204,18 @@ def all_cards(): return False info("Popup 'Explorer le programme' reçue") - wait_until_visible(By.CSS_SELECTOR, '[aria-label="Boîte de dialogue Récompenses"]', timeout=10, browser=driver) + wait_until_visible(By.ID, "welcome-tour", timeout=5, browser=driver) custom_sleep(1.5) - rewards_box = driver.find_element(By.CSS_SELECTOR, '[aria-label="Boîte de dialogue Récompenses"]') - close_button = rewards_box.find_element(By.CSS_SELECTOR, '[aria-label="Fermer"]') - close_button.click() + + welcome_tour = driver.find_element(By.ID, "welcome-tour") + interest_button_box = welcome_tour.find_element(By.CLASS_NAME, "interest-buttons") + interests = interest_button_box.find_elements(By.CLASS_NAME, "ng-binding") + debug("Got the following interests: "+str(interests)) + random.choice(interests).click() # Choose interest + custom_sleep(1.5) + + claim_button = welcome_tour.find_element(By.ID, "claim-button") + claim_button.click() # submit custom_sleep(1.5) return True From 01416c0e1193a6fa9af056ae2896c8814b628554 Mon Sep 17 00:00:00 2001 From: augustin64 Date: Sat, 13 Apr 2024 11:01:25 +0200 Subject: [PATCH 8/8] Check before scrolling, but should be good to merge ! --- V6.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/V6.py b/V6.py index 3b0c65c..94e6920 100755 --- a/V6.py +++ b/V6.py @@ -266,9 +266,9 @@ def all_cards(): continue custom_sleep(1.5) + check_welcome_tour() driver.execute_script("arguments[0].scrollIntoView();", card_list[i]) custom_sleep(1.5) - check_welcome_tour() card_list[i].click() if len(driver.window_handles) > 1: @@ -283,8 +283,8 @@ def all_cards(): if "mee-icon-AddMedium" not in card_list[i].get_attribute("innerHTML"): continue - driver.execute_script("arguments[0].scrollIntoView();", card_list[i]) check_welcome_tour() + driver.execute_script("arguments[0].scrollIntoView();", card_list[i]) card_list[i].click() driver.switch_to.window(driver.window_handles[1])