from playwright.sync_api import sync_playwright, expect, Page, BrowserContext from playwright_stealth import stealth_sync from actions.quiz import play from tools.logger import * from tools.logger import * def all_cards(page: Page): # input("1") page.goto("https://rewards.bing.com") page.wait_for_load_state('load') daily_cards(page) more_cards(page) def daily_cards(page: Page): for i in range(1, 4): card = page.locator(f'#daily-sets > mee-card-group:nth-child(7) > div > mee-card:nth-child({i}) > div') if "mee-icon-AddMedium" not in card.inner_html(): info(f'Daily Card {i} : {"Validated" if "mee-icon-AddMedium" not in card.inner_html() else "Failure"}') continue with page.expect_popup() as page1_info: card.click() page1 = page1_info.value stealth_sync(page1) page1.wait_for_load_state('load') try: selector = page1.get_by_role("button", name="Accepter") expect(selector).to_be_visible(timeout=10_000) selector.click() except AssertionError as e: pass # The RGPD button should not be there in the first place play(page1) page1.close() page.reload() info(f'Daily Card {i} : {"Validated" if "mee-icon-AddMedium" not in card.inner_html() else "Failure"}') def more_cards(page: Page): c = 1 while c < 15: # todo I don't really know why it stops without raising any errors, but I guess it's fine card = page.locator(f"#more-activities > div > mee-card:nth-child({c})") try: expect(card).to_be_visible(timeout=10_000) except Exception as e: # The card probably does not exist debug(e) break if "mee-icon-AddMedium" in card.inner_html(): info(f"Playing more cards {c}.") with page.expect_popup() as page1_info: card.click() page1 = page1_info.value stealth_sync(page1) page1.wait_for_load_state('load') play(page1) page1.close() page.reload() info(f'More Card {c} : {"Validated" if "mee-icon-AddMedium" not in card.inner_html() else "Failure"}') c += 1