尧图网络 高端网站定制 · 原创设计
免费咨询热线
400-888-6620
免费获取方案
winuia-auto 为uiautomation 的替代者, 使用xpath进行定位
winuia-auto 为uiautomation 的替代者1. 元素检查import winuia as autoauto.InspectElement()提示Ctrl 鼠标悬停到元素上2. 使用xpath定位 - 亚马逊账号登录import re import time import winuia as auto from lxml import etree from winuia import UIXPath def dialog_close(): # 点击弹窗 window auto.WindowControl(ClassNameChrome_WidgetWin_1, RegexName.*Google Chrome) btn_close window.ButtonControl(NameClose, LocalizedControlType按钮) if btn_close.Exists(1): btn_close.SafeClick() def login_judge_xpath(asin): # 亚马逊登录 # 判断是否需要登录 window auto.WindowControl(ClassNameChrome_WidgetWin_1, RegexName.*Google Chrome) # 访问url #browser auto.Browser(window) #window.Restore() #url browser.get_current_url() #print(url) ## href fhttps://www.amazon.com/product-reviews/{asin}/?pageNumber1sortByrecentfilterByStarfour_star #href fhttps://www.amazon.com/product-reviews/{asin} ## 打开新窗口打开新网址 #if product-reviews not in url: #browser.new_tab() #browser.navigate(href, timeout30) #else: #browser.navigate(href, timeout30) xpath UIXPath(window) text2 xpath.find(//Text[contains(Name, Sign in or crea) or contains(Name, 登录)]) time.sleep(5) if not text2.Exists(1): return # 输入邮箱 email xxxx # input_email xpath.find(//Text[contains(Name, Enter mobile number or email) or contains(Name, 输入手机号码或邮箱)]) input_email xpath.find(//Edit[AutomationIdap_email_login]) print(input_email) input_email.Press_Hotkey(ctrl, a) input_email.Press_Hotkey(backspace) auto.SetClipboardText(email) input_email.SetFocus() input_email.Press_Hotkey(ctrl, v) next_btn xpath.find(//Button[NameContinue or Name继续]) next_btn.Click() time.sleep(1.5) # windows 安全中心 cancel_btn xpath.find(//Button[NameCancel or Name取消]) if cancel_btn.Exists(1): cancel_btn.Click() time.sleep(0.5) next_btn.Click() for i in range(10): pwd_edit xpath.find(//Edit[AutomationIdap_password]) if pwd_edit.Exists(1): break time.sleep(1) # 输入密码 passwordxxxx pwd_edit xpath.find(//Edit[AutomationIdap_password]) # window.EditControl(Name密码) pwd_edit.SetFocus() auto.SetClipboardText(password) pwd_edit.Press_Hotkey(ctrl, v) # 点击登录 log_btn xpath.find(//Button[AutomationIdsignInSubmit]) # window.ButtonControl(Name登录) log_btn.Click() # 保存密码弹窗 for i in range(8): no_use window.ButtonControl(Name不用了) if no_use.Exists(1): no_use.Click() break time.sleep(1)
RELATED

相关推荐

Oh My PPT风格体系详解:90+内置风格Skill怎么选,还能创建自己的专属风格包

Oh My PPT风格体系详解:90+内置风格Skill怎么选,还能创建自己的专属风格包

Oh My PPT风格体系详解:90内置风格Skill怎么选,还能创建自己的专属风格包 【免费下载链接】oh-my-ppt Describe what you need — a presentation, lesson, or story — and let the AI build clean, beautiful HTML slides for you. Local-first. Works…

📅 2026/10/8 6:45:16
嵌入式电源保护实战:eFuse硬保护与MCU智能监控方案

嵌入式电源保护实战:eFuse硬保护与MCU智能监控方案

做嵌入式的人,早晚都会碰到这样一个问题:好好的板子,一上电就烧,烧的还不是芯片本身,而是电源路径上那颗不起眼的 DC/DC、传感器模块或者通信模组。去年我在调试一套工业 I/O 控制板时,现场反复出现过这种问…

📅 2026/10/8 6:40:16
高炉工艺流程照抄教材,查重和 AI 检测一起飘红

高炉工艺流程照抄教材,查重和 AI 检测一起飘红

冶金工程专业的毕业论文,"工艺流程"那一章几乎是标红重灾区:高炉炼铁从原料入炉讲到铁水出炉,烧结、球团、还原、造渣、脱硫——每一步教材上都有现成段落,写起来"顺理成章",交上去查重飘红、AI 检…

📅 2026/10/8 6:40:16
MORE NEWS

更多资讯

📰

Python Agent 踩坑实录:第一次写 Agent,我忘了加一行代码,循环跑了 200 次

Python Agent 踩坑实录:第一次写 Agent,我忘了加一行代码,循环跑了 200 次 摘要:本文从一次"初学者写 Agent 忘了加最大步数限制、循环跑了 200 次才停"的经历出发,分析 Agent 循环失控的三个常见原因&#…

📰

工业级电源路径保护:TPS259483AYWPR与STM32F405ZG协同设计

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

📰

微内核工具系统设计与AI辅助故障排查实践

1. 工具系统的定位与设计取舍1.1 为什么内核需要一套自己的工具系统写内核最痛苦的一件事,不是功能实现不出来,而是功能写好了之后不知道它到底跑得对不对。前几篇我们把DSH的调度器、内存管理、设备框架都搭了起来,内核能开机、能执行任务了…

📰

17、触摸事件分发流程:MotionEvent的封装,从InputDispatcher到ViewRootImpl

17.1 事件封装的起点:InputDispatcher好,我们直接进入正题。上一章我们聊到InputDispatcher从队列里取出事件,准备发给目标窗口。但这里有个关键动作——事件封装。说白了,就是把原始的输入数据,包装成一个Java层能识别…

📰

90DaysOfDevOps Ansible 实战:Tags、Variables、Inventory 与 MySQL 数据库服务器自动化配置

文档/教程 【免费下载链接】90DaysOfDevOps This repository started out as a learning in public project for myself and has now become a structured learning map for many in the community. We have 3 years under our belt covering all things DevOps, including Pri…

📰

Agent Safehouse:AI编程助手的安全沙箱,3条命令防住提示注入

Agent Safehouse:AI编程助手的安全沙箱,3条命令防住提示注入 【免费下载链接】agent-safehouse Sandbox your local AI agents so they can read/write only what they need 项目地址: https://gitcode.com/gh_mirrors/ag/agent-safehouse Agent …

TODAY

今日更新

THIS WEEK

本周精选

THIS MONTH

本月热门

读完文章,想聊聊您的网站?

告诉我们您的行业与需求,资深顾问一对一梳理方案与报价,全程免费。

📞 💬