test1
This commit is contained in:
47
algam.py
Normal file
47
algam.py
Normal file
@@ -0,0 +1,47 @@
|
||||
from pywinauto.application import Application
|
||||
from pywinauto.keyboard import send_keys
|
||||
from pywinauto import mouse
|
||||
from pywinauto.timings import Timings
|
||||
|
||||
# Увеличиваем таймауты по умолчанию (в секундах)
|
||||
Timings.window_find_timeout = 10
|
||||
Timings.after_clickinput_wait = 1
|
||||
|
||||
def open_application():
|
||||
try:
|
||||
app = Application(backend="uia").start("explorer.exe")
|
||||
main_window = app.window(title="Проводник", control_type="Window")
|
||||
main_window.wait("visible", timeout=10)
|
||||
return app
|
||||
except Exception as e:
|
||||
print(f"Ошибка при открытии приложения: {e}")
|
||||
return None
|
||||
|
||||
def close_application(app):
|
||||
if app:
|
||||
app.kill()
|
||||
|
||||
def click_left_button(app, button_text):
|
||||
try:
|
||||
main_window = app.window(title="Проводник", control_type="Window")
|
||||
button = main_window.child_window(title=button_text, control_type="Button")
|
||||
button.click_input(button="left")
|
||||
except Exception as e:
|
||||
print(f"Не удалось нажать кнопку '{button_text}': {e}")
|
||||
|
||||
def input_text(app, field_text, input_text):
|
||||
try:
|
||||
main_window = app.window(title="Проводник", control_type="Window")
|
||||
field = main_window.child_window(title=field_text, control_type="Edit")
|
||||
field.type_keys(input_text)
|
||||
except Exception as e:
|
||||
print(f"Не удалось ввести текст в поле '{field_text}': {e}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = open_application()
|
||||
if app:
|
||||
try:
|
||||
click_left_button(app, "Этот компьютер")
|
||||
input_text(app, "Адресная строка", "C:\\")
|
||||
finally:
|
||||
close_application(app)
|
||||
Reference in New Issue
Block a user