Files
auto_test/main.py
2025-11-06 10:42:02 +08:00

63 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from re import T
from DrissionPage import Chromium
# 发送请求告知服务器执行完成
def send_complete():
print('发送信息告知服务器脚本执行完成')
url = ''
def main(http: str):
"""
使用给定的 http 句柄接管已打开的指纹浏览器并执行示例登录流程
Args:
http (str): 浏览器的 http 句柄字符串
Returns:
None
"""
# 启动或接管浏览器,并获取标签页对象
print(f'使用 http 接管浏览器: {http}')
tab = Chromium(http).new_tab()
# 跳转到登录页面
tab.get('https://gitee.com/login')
# 定位到账号文本框,获取文本框元素
ele = tab.ele('#user_login')
# 输入账号
ele.input('您的账号')
# 定位到密码文本框并输入密码
tab.ele('#user_password').input('您的密码')
# 点击登录按钮
tab.ele('@value=登 录').click()
# while True:
# print(1)
# time.sleep(5)
if __name__ == '__main__':
"""
脚本入口:支持从命令行参数或环境变量读取 http 并调用 main
- 命令行python project/test/log.py <http>
- 环境变量BROWSER_HTTP=<http> python project/test/log.py
"""
import os
import sys
import time
http = os.getenv('BROWSER_HTTP') or (sys.argv[1] if len(sys.argv) > 1 else None)
if not http:
print('缺少 http 参数:请通过命令行传入或设置环境变量 BROWSER_HTTP')
sys.exit(1)
print(f'接收到 http: {http}')
try:
main(http)
print('脚本执行完成')
except Exception as e:
print(f'脚本执行异常: {e}')
sys.exit(2)