闽公网安备 35020302035485号
2.重复某些UI操作步骤复现一些极少概率才有可能触发的bug。
pip install pyautogui

import pyautogui
# 堆代码 duidaima.com
# 找到按钮图像位置 (这里需要一张按钮的截图,命名为'button.png')
button_location = pyautogui.locateOnScreen('button.png')
if button_location:
# 计算按钮中心点位置
button_center = pyautogui.center(button_location)
# 移动鼠标至按钮中心并点击
pyautogui.moveTo(button_center)
pyautogui.click()
else:
print("Button not found on screen.")
运行效果:
pip install pywinauto代码:
from pywinauto.application import Application
import time
# 堆代码 duidaima.com
# 启动应用程序
app = Application(backend="uia").start("your path/..../WpfApp1.exe")
time.sleep(1) # Wait for 5 seconds
# 选择窗口
dlg = app.window(title='MainWindow')
# 在密码框中输入内容 , control_type="TextBox"
dlg.child_window(auto_id="TxboxPwd").type_keys('123')
# 点击登录按钮 , control_type="Button"
dlg.child_window(auto_id="BtnOK").click()
WPF代码:<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBox x:Name="TxboxPwd" Width="200" Height="25" ></TextBox>
<Button x:Name="BtnOK" Width="200" Height="25" Content="Button" Click="Button_Click" Margin="0,20,0,0"></Button>
</StackPanel>
</Window>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
TxboxPwd.Text = "hello,py";
}
private void Button_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show(TxboxPwd.Text);
}
}
运行效果: