from playwright.sync_api import Playwright, sync_playwright, expect def run(playwright: Playwright) -> None: user_data_dir = "/Users/kaka/chrome" args = [ '--disable-blink-features=AutomationControlled', f"--disable-extensions", f"--disable-popup-blocking", f"--ignore-certificate-errors", f"--disable-plugins-discovery", f'--no-first-run', f'--no-service-autorun', f'--no-default-browser-check', # f'--no-startup-window', f'--disable-dev-shm-usage', # f"--disable-extensions-except={cookie_extension},{path_to_extension}", ] headless = False context = playwright.chromium.launch_persistent_context( user_data_dir, channel="chrome", device_scale_factor=1, devtools=False, headless=False, args=args ) browser = context.browser # browser = playwright.chromium.launch(headless=False, channel="chrome") # context = browser.new_context() page = context.new_page() page.set_default_timeout(10000) page.goto("https://cnlogin.cainiao.com/login?appKey=12497914&istb=true&redirectURL=https%3A%2F%2Fmerchant.finance.cainiao.com%2Ffunds%2Fwaterlevel%2FCustProdWaterLevelReportConfig.htm&showae=true&showin=false&showdd=false&tbUserName=&sub=&type=ML&domain=&lang=&isNewLogin=&targetAccount=&meta=&isEnterprise=&isQTb=false&isCnSSOTb=false") # Usename: fundpark; Password: Fundpark2019@ username = page.frame_locator("#J_taobao iframe").locator('#fm-login-id') username.click() username.fill('账号') userpass = page.frame_locator("#J_taobao iframe").locator('#fm-login-password') userpass.click() userpass.fill('密码') page.frame_locator("#J_taobao iframe").frame_locator("#baxia-dialog-content").get_by_text("请按住滑块,拖动到最右边").click() # 获取拖动按钮位置并拖动 dropbutton = page.frame_locator("#J_taobao iframe").frame_locator("#baxia-dialog-content").locator("#nc_1_n1z") box = dropbutton.bounding_box() page.mouse.move(box['x'] + box['width'] / 2, box['y'] + box['height'] / 2) page.mouse.down() mov_x = box['x'] + box['width'] / 2 + 260 page.mouse.move(mov_x, box['y'] + box['height'] / 2) page.mouse.up() # 登录按钮 page.frame_locator("#J_taobao iframe").locator(".fm-submit").click() # 快速进入 page.frame_locator("#J_taobao iframe").locator(".fm-submit").click() # 打印页面的标题 print(page.title()) page.wait_for_timeout(100000) context.close() browser.close() with sync_playwright() as playwright: run(playwright)
标签:box,playwright,--,菜鸟,frame,locator,后台,page From: https://www.cnblogs.com/kaka0318/p/17037765.html