3 changed files with 12 additions and 84 deletions
@ -1,76 +0,0 @@ |
|||||||
import uiautomation as auto |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 遍历所有控件 找到 |
|
||||||
def findAndClickFileImportShow(control, depth=0): |
|
||||||
for child in control.GetChildren(): |
|
||||||
# print(child) |
|
||||||
# print(' ' * depth + f"{child.ControlType}: {child.Name} | {child.AutomationId}") |
|
||||||
if child.Name == "切片及打印": |
|
||||||
# 点击和 child 同组的第二个元素(即 control 的子控件中的第二个) |
|
||||||
siblings = control.GetChildren() # 获取所有同级元素 |
|
||||||
# print(f"\n找到目标控件: {child.Name}") |
|
||||||
# print(f"同级元素数量: {len(siblings)}") |
|
||||||
|
|
||||||
# 打印所有同级元素信息,方便调试 |
|
||||||
for i, sibling in enumerate(siblings): |
|
||||||
marker = " <-- 这是找到的目标" if sibling == child else "" |
|
||||||
print(f" 同级元素[{i}]: {sibling.ControlType} | {sibling.Name} | {sibling.AutomationId}{marker}") |
|
||||||
|
|
||||||
# 确保有至少2个同级元素 |
|
||||||
if len(siblings) >= 2: |
|
||||||
target = siblings[2] # 第二个元素(索引从0开始) |
|
||||||
print(f"\n准备点击同级第二个元素:") |
|
||||||
print(f" 控件类型: {target.ControlType}") |
|
||||||
print(f" 控件名称: {target.Name}") |
|
||||||
print(f" 自动化ID: {target.AutomationId}") |
|
||||||
|
|
||||||
# 尝试多种点击方式 |
|
||||||
try: |
|
||||||
# 方法1: 直接点击 |
|
||||||
target.Click() |
|
||||||
print("✓ 使用 Click() 方法点击成功") |
|
||||||
return True |
|
||||||
except Exception as e: |
|
||||||
print(f"✗ Click() 失败: {e}") |
|
||||||
try: |
|
||||||
# 方法2: 使用 Invoke(如果是可调用的控件) |
|
||||||
target.Invoke() |
|
||||||
print("✓ 使用 Invoke() 方法点击成功") |
|
||||||
return True |
|
||||||
except Exception as e2: |
|
||||||
print(f"✗ Invoke() 失败: {e2}") |
|
||||||
try: |
|
||||||
# 方法3: 先设置焦点再点击 |
|
||||||
target.SetFocus() |
|
||||||
import time |
|
||||||
time.sleep(0.1) |
|
||||||
target.Click() |
|
||||||
print("✓ 使用 SetFocus() + Click() 方法点击成功") |
|
||||||
return True |
|
||||||
except Exception as e3: |
|
||||||
print(f"✗ SetFocus() + Click() 失败: {e3}") |
|
||||||
# 方法4: 使用鼠标点击坐标 |
|
||||||
try: |
|
||||||
rect = target.BoundingRectangle |
|
||||||
# BoundingRectangle 是一个矩形对象,计算中心点 |
|
||||||
x = rect.left + ((rect.right - rect.left) / 2) |
|
||||||
y = rect.top + ((rect.bottom - rect.top) / 2) |
|
||||||
auto.Click(x, y) |
|
||||||
print(f"✓ 使用坐标点击成功: ({x}, {y})") |
|
||||||
return True |
|
||||||
except Exception as e4: |
|
||||||
print(f"✗ 坐标点击失败: {e4}") |
|
||||||
else: |
|
||||||
print(f"✗ 同级元素数量不足,只有 {len(siblings)} 个") |
|
||||||
return False |
|
||||||
else: |
|
||||||
findAndClickFileImportShow(child, depth + 1) |
|
||||||
|
|
||||||
def begingClickSliceing(): |
|
||||||
control = auto.WindowControl(searchDepth=1, Name='赛纳3D打印控制系统 V1.4.3.2') |
|
||||||
clickRes = findAndClickFileImportShow(control) |
|
||||||
return clickRes |
|
||||||
|
|
||||||
# clickFileIMportShow() |
|
||||||
Loading…
Reference in new issue