Files
to_session/web_process/text.py
Administrator a0720d80dc fefdwef
2025-11-12 12:54:37 +08:00

101 lines
4.4 KiB
Python

import time
from loguru import logger
def login_metamask(self, tab, net_work: {}):
page = tab
logger.info('metamask配置开始...')
wallet_url = 'chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/home.html#'
page.get(wallet_url)
time.sleep(2)
for _ in range(5):
if not tab.states.is_loading:
break
time.sleep(1)
for _ in range(10):
if '即将进入去中心化网络' in tab.html and '登录' in tab.html:
logger.success('即将进入去中心化网络 登录')
tab.ele('#password').input(12345678)
time.sleep(1.5)
page.ele("xpath://button[@data-testid='unlock-submit']").click(by_js=True)
break
time.sleep(1)
else:
try:
page.ele(
'.mm-box mm-button-icon mm-button-icon--size-sm mm-banner-base__close-button mm-box--margin-left-auto mm-box--display-inline-flex mm-box--justify-content-center mm-box--align-items-center mm-box--color-icon-default mm-box--background-color-transparent mm-box--rounded-lg').click()
except:
pass
page.ele('#onboarding__terms-checkbox').click()
page.ele("xpath://button[@class='button btn--rounded btn-primary']").click()
page.wait(2)
page.ele("xpath://button[@class='button btn--rounded btn-primary btn--large']").click()
password_inputs = page.eles("xpath://input[@class='form-field__input']")
password_inputs[0].input(12345678)
password_inputs[1].input(12345678)
page.ele("xpath://label[@class='create-password__form__terms-label']").click(by_js=True)
page.ele("xpath://button[@data-testid='create-password-wallet']").click(by_js=True)
time.sleep(2)
# 稍后提醒我
page.ele("xpath://button[@data-testid='secure-wallet-later']").click(by_js=True)
page.ele("xpath://input[@data-testid='skip-srp-backup-popover-checkbox']").click(by_js=True)
page.ele("xpath://button[@data-testid='skip-srp-backup']").click(by_js=True)
page.ele("xpath://button[@data-testid='onboarding-complete-done']").click(by_js=True)
page.ele("xpath://button[@data-testid='pin-extension-next']").click(by_js=True)
page.ele("xpath://button[@data-testid='pin-extension-done']").click(by_js=True)
page.ele(
"xpath://button[@class='mm-box mm-text mm-button-base mm-button-base--size-md mm-button-primary mm-text--body-md-medium mm-box--margin-top-8 mm-box--padding-0 mm-box--padding-right-4 mm-box--padding-left-4 mm-box--display-inline-flex mm-box--justify-content-center mm-box--align-items-center mm-box--width-full mm-box--color-primary-inverse mm-box--background-color-primary-default mm-box--rounded-pill']").click(
by_js=True)
# 添加新网络
add_net_addr = 'chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/home.html#settings/networks/add-network'
page.get(add_net_addr)
time.sleep(2)
page.ele("@data-testid=network-form-network-name").input(net_work['name'])
page.ele("@data-testid=network-form-rpc-url").input(net_work['rpc_url'])
page.ele("@data-testid=network-form-chain-id").input(net_work['link_id'])
page.ele("@data-testid=network-form-ticker-input").input(net_work['symbol'])
page.ele("@data-testid=network-form-block-explorer-url").input(net_work['chain_url'])
page.wait(3)
page.ele(".button btn--rounded btn-primary").click(by_js=True)
time.sleep(0.5)
page.ele(".mm-box mm-text mm-text--body-sm mm-box--color-primary-inverse").click(by_js=True)
time.sleep(4)
# 开始导入账户
page.ele("xpath://button[@data-testid='account-menu-icon']").click(by_js=True)
page.ele("xpath://button[@data-testid='multichain-account-menu-popover-action-button']").click(by_js=True)
page.eles(
'.mm-box mm-text mm-button-base mm-button-base--size-sm mm-button-link mm-text--body-md-medium mm-box--padding-0 mm-box--padding-right-0 mm-box--padding-left-0 mm-box--display-inline-flex mm-box--justify-content-center mm-box--align-items-center mm-box--color-primary-default mm-box--background-color-transparent')[
1].click(by_js=True)
page.ele("#private-key-box").input(self.private_key)
page.ele("@data-testid=import-account-confirm-button").click(by_js=True)
time.sleep(1)
logger.info('metamask配置完成...')