from playwright.sync_api import sync_playwright

URL = "https://psy5mp.xinliyun.cn/"
ID_CARD = "410323200512060159"
PASSWORD = "000000"

LOGIN_ID_INPUT = "#van-field-1-input"
LOGIN_PWD_INPUT = "#van-field-2-input"
LOGIN_BTN = "#app > div > form > div.form-act > button"

PAPER_ENTRY = "#app > div > div.layout-content > div.van-cell.van-cell--center.van-cell--clickable > div"
PAPER_START = "#app > div > div.paper-desc > div.paper-act.van-safe-area-bottom > button"

FIRST_OPTION = "#app > div > div.paper-quiz-wrapper > div.paper-detail > div.van-radio-group > div > div:nth-child(1)"


def main() -> None:
    with sync_playwright() as p:
        browser = p.chromium.launch(headless=False)
        page = browser.new_page()

        page.goto(URL, wait_until="domcontentloaded")

        # 登录
        page.fill(LOGIN_ID_INPUT, ID_CARD)
        page.fill(LOGIN_PWD_INPUT, PASSWORD)
        page.click(LOGIN_BTN)

        # 进入待测量表列表
        page.wait_for_selector(PAPER_ENTRY)
        page.click(PAPER_ENTRY)

        # 进入测评介绍页并开始
        page.wait_for_selector(PAPER_START)
        page.click(PAPER_START)

        # 连续选择第一个选项 90 次
        for _ in range(90):
            page.wait_for_selector(FIRST_OPTION)
            page.click(FIRST_OPTION)

        page.wait_for_timeout(1000)
        browser.close()


if __name__ == "__main__":
    main()
