Created
January 25, 2023 21:49
-
-
Save kmcquade/4341e909edc2d510230561e3e0319e97 to your computer and use it in GitHub Desktop.
pw_example.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Gmail doesn't work using regular recording. It will only work if you run the recording script and then wrap the recorded script in this | |
""" | |
from playwright.sync_api import Playwright, sync_playwright, expect | |
from playwright._impl._api_types import Error as PlaywrightError | |
def run(pw: Playwright) -> None: | |
args = [ | |
"--disable-dev-shm-usage", | |
"--disable-blink-features=AutomationControlled", | |
"--disable-component-extensions-with-background-pages" | |
] | |
chrome_path = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" | |
browser = pw.chromium.launch(headless=False, args=args, executable_path=chrome_path) | |
# Setup context however you like. | |
context = browser.new_context() # Pass any options | |
context.route('**/*', lambda route: route.continue_()) | |
page = context.new_page() | |
print("page.pause() will bring up Playwright inspector") | |
page.pause() | |
page.goto("https://www.gmail.com") | |
page.goto("https://accounts.google.com/v3/signin/identifier?dsh=S-620455614%3A1672708369991153&continue=https%3A%2F%2Fmail.google.com%2Fmail%2Fu%2F0%2F&emr=1&followup=https%3A%2F%2Fmail.google.com%2Fmail%2Fu%2F0%2F&osid=1&passive=1209600&service=mail&flowName=GlifWebSignIn&flowEntry=ServiceLogin&ifkv=AeAAQh5TkBG0ZPm32Fy-eQrvgbLuQ5pU2MRdjEsdiW7-yntmqdz_TgxyjXNPfIR3A1kSKXxyajW7tg") | |
page.get_by_role("textbox", name="Email or phone").fill("integrationtests") | |
page.get_by_role("button", name="Next").click() | |
print("Gmail would normally say, 'Couldnt sign you in - this browser or app may not be secure'. But here, it will allow you to type in a password.") | |
def main(): | |
with sync_playwright() as pw: | |
run(pw) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment