Add logout functionality to DiscreteMaterialPlanExtractor for improved session management
This commit is contained in:
@@ -234,6 +234,9 @@ class DiscreteMaterialPlanExtractor:
|
||||
)
|
||||
downloaded_files.append(downloaded_file)
|
||||
|
||||
# 执行账号注销
|
||||
self._print("\n开始执行账号注销...")
|
||||
self.logout(main_frame)
|
||||
|
||||
# 转换并合并文件
|
||||
if downloaded_files:
|
||||
@@ -245,12 +248,44 @@ class DiscreteMaterialPlanExtractor:
|
||||
self._print(f"\n=== 全部完成 ===")
|
||||
self._print(f"最终文件: {output_file}")
|
||||
|
||||
|
||||
|
||||
# 关闭浏览器
|
||||
context.close()
|
||||
browser.close()
|
||||
|
||||
return output_file
|
||||
|
||||
def logout(self, main_frame):
|
||||
"""执行账号注销"""
|
||||
# 元素1:账号菜单按钮(logo 图标)
|
||||
self._print("点击账号菜单按钮...")
|
||||
main_frame.get_by_role("img", name="logo").click()
|
||||
|
||||
# 等待菜单出现
|
||||
import time
|
||||
time.sleep(1)
|
||||
|
||||
# 元素2:"退出登录"按钮
|
||||
self._print("点击退出登录按钮...")
|
||||
main_frame.get_by_text("退出登录").click()
|
||||
|
||||
# 等待确认框出现
|
||||
time.sleep(1)
|
||||
|
||||
# 元素3:退出登录确认框(判断是否出现)
|
||||
self._print("等待退出登录确认框...")
|
||||
try:
|
||||
confirm_text = main_frame.get_by_text("退出确定要退出当前账号吗?")
|
||||
self._print("找到确认框,点击确定按钮")
|
||||
|
||||
# 元素4:确认按钮
|
||||
main_frame.get_by_role("button", name="确定(Y)").click()
|
||||
except:
|
||||
self._print("未找到确认框,可能已自动退出")
|
||||
|
||||
time.sleep(2) # 等待注销完成
|
||||
|
||||
|
||||
def main():
|
||||
"""测试函数"""
|
||||
|
||||
Reference in New Issue
Block a user