Dismiss modals
This commit is contained in:
parent
c1ce0db188
commit
991e4e939a
|
@ -7,7 +7,7 @@ import urllib.parse
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
import lxml.html
|
import lxml.html
|
||||||
from playwright.sync_api import Playwright, expect, sync_playwright
|
from playwright.sync_api import Page, Playwright, expect, sync_playwright
|
||||||
|
|
||||||
auth_file = os.path.expanduser("~/lib/auth/google.json")
|
auth_file = os.path.expanduser("~/lib/auth/google.json")
|
||||||
data_loc = os.path.expanduser("~/lib/google_stocks")
|
data_loc = os.path.expanduser("~/lib/google_stocks")
|
||||||
|
@ -34,6 +34,25 @@ def data_filename(page_type: str, ext: str = "html") -> str:
|
||||||
return os.path.join(data_loc, now_str + f"_{page_type}.{ext}")
|
return os.path.join(data_loc, now_str + f"_{page_type}.{ext}")
|
||||||
|
|
||||||
|
|
||||||
|
def accept_cookies(page: Page) -> None:
|
||||||
|
"""Check for the 'Accept all' button and click it if found."""
|
||||||
|
accept_button_selector = "button:has-text('Accept all')"
|
||||||
|
accept_button = page.locator(accept_button_selector)
|
||||||
|
if accept_button.is_visible():
|
||||||
|
accept_button.click()
|
||||||
|
|
||||||
|
|
||||||
|
def stay_signed_out(page: Page) -> None:
|
||||||
|
"""Check for the 'Stay signed out' button and click it if found."""
|
||||||
|
# Selector for the 'Stay signed out' button
|
||||||
|
button_selector = "text=Stay signed out"
|
||||||
|
|
||||||
|
# Check for the button and click it if found
|
||||||
|
stay_signed_out_button = page.locator(button_selector)
|
||||||
|
if stay_signed_out_button.is_visible():
|
||||||
|
stay_signed_out_button.click()
|
||||||
|
|
||||||
|
|
||||||
class Index:
|
class Index:
|
||||||
"""Stock market index."""
|
"""Stock market index."""
|
||||||
|
|
||||||
|
@ -71,6 +90,10 @@ class Index:
|
||||||
page = context.new_page()
|
page = context.new_page()
|
||||||
|
|
||||||
page.goto(self.search_url, wait_until="domcontentloaded")
|
page.goto(self.search_url, wait_until="domcontentloaded")
|
||||||
|
|
||||||
|
accept_cookies(page)
|
||||||
|
stay_signed_out(page)
|
||||||
|
|
||||||
expect(page.get_by_text("Market Summary")).to_be_visible()
|
expect(page.get_by_text("Market Summary")).to_be_visible()
|
||||||
|
|
||||||
html = page.content()
|
html = page.content()
|
||||||
|
|
Loading…
Reference in a new issue