QT automation with pywinauto - python

I'm trying to automate a QT app using pywinauto, the problem is pywinauto seems unable to click or select most objects and when it does they seem to be completely random to the ones I specified. Even using functions such as "click_input" execute properly, but the item is never actually clicked. Pywinauto apparently does recognize the button I'm trying to click and even prints it as an "pywinauto.application.WindowSpecification" object. I've noticed that pywinauto has some trouble with QT applications so any help would be appreciated. Thank you.
anki_App = Application(backend="uia").start(anki_Path)
anki_App.top_window().wait("Visible") #Wait for Anki's sync to server
anki = anki_App.window(title_re=r".* - Anki", class_name="AnkiQt")
anki['Import File'].click_input()
Snippet from results of anki.print_control_identifiers() since the content is too large.
Button - 'Import File' (L1751, T875, R1867, B910)
['Import File', 'Import FileButton', 'Button6']
child_window(title="Import File", control_type="Button")
Edit: Made some recommended changes, but the problem still remains. The click event doesn't seem to bring any errors yet no "click" actually happens.

After asking around in Pywinsauto's github community I was able to solve it in the following way:
anki_App = Application(backend="uia").start(anki_Path)
anki_App.top_window().wait("Visible") #Wait for Anki's sync to server
anki = anki_App.window(title_re=r".* - Anki", class_name="AnkiQt")
anki['Browse'].click_input(coords=(anki['Browse'].rectangle().left -1, anki['Browse'].rectangle().top -1), absolute = True)
Problem was that the coordinates were wrong. They were pretty close though, so clicking the upper left corner was all that needed to be done. Again, many thanks to the user airelil for helping me figuring out the problem.
Link to the issue

Related

WxPython exit button doesn´t always works

I am using a code designed by another person in MAC OS. I am using Windows instead and have slightly modified it, but the problem comes when using the GUI that is created.
I have already dealt with a similar issue with a slider. Once I pressed the slider, I couldn´t release it or press another button. I was forced to quit the GUI and start again. I solved it by changing the event command from EVT_COMMAND_SCROLL to EVT_COMMAND_SCROLL_THUMBTRACK. However I did not understand why it worked in MAC OS and does not work in Windows.
Now, I want to close the GUI with the typical cross inside the red button in the right corner of the window. I can do it if it is the first order I do in the GUI. If I first press any button or slider, the exit button does not work.
It made me consider if a major problem is hidden in the code which I am not seeing. I am new at wxPython, which is the module used in the code.
I just ask for your opinion and hope it is a basic error.
Thanks very much

Using Winium (+ Selenium) with python only allows me to open the app, but then won't interact with it?

When I try to run any kind of code using winium, it will open the app, but then won't execute any of the code afterwards. It's not as if it throws up an error, it just hangs there and won't move on.
I Am using Python 3.7 on a Windows 10 PC.
I have tried the two 'magic' examples that are listed on the github wiki page for Winium, but even that doesn't work. I am able to use selenium to do automated web testing, so I don't think the selenium module is the issue. I have tried importing the time module and making it sleep for 10 seconds in between lines but this has no effect on the outcome.
from selenium import webdriver
driver = webdriver.Remote(
command_executor='http://localhost:9999',
desired_capabilities={
"debugConnectToRunningApp": 'false',
"app": r"C:/windows/system32/calc.exe"
})
# THIS IS WHERE IT SEEMS TO PAUSE INDEFINITELY
window = driver.find_element_by_class_name('CalcFrame')
view_menu_item = window.find_element_by_id('MenuBar').find_element_by_name('View')
view_menu_item.click()
view_menu_item.find_element_by_name('Scientific').click()
view_menu_item.click()
view_menu_item.find_element_by_name('History').click()
window.find_element_by_id('132').click()
window.find_element_by_id('93').click()
window.find_element_by_id('134').click()
window.find_element_by_id('97').click()
window.find_element_by_id('138').click()
window.find_element_by_id('121').click()
driver.close()
I would expect it to press the corresponding buttons, but it doesn't seem to do anything except open the calculator app.
I think this example is written for an older version of calculator. In Windows 10, the "Scientific" button is under the Menu button.
You'll have to find the menu button, click it, and then look for the element "Scientific" in the list.
Also, the numeric values for your arithmatic case are not correct. Pick up a UI inspector tool (inspect.exe, uispy, etc...) to make sure you are targeting the elements correctly.

Pywinauto find process window and focus it

My current situation is that I open a process, which opens in a random location (thats how this process works).
I have the process PID so I need to somehow focus this window, and move it to the center of my screen.
Im doing something wrong as I can't even set focus on that window... tried it with different apps and got the same result...
The way I select the window -
appl = pywinauto.application.Application()
appl.connect(process=824)
app_dialog = appl.top_window_()
app_dialog.Minimize()
app_dialog.Maximize()
##app_dialog.SetFocus() ##doesn't work aswell
##pywinauto.win32functions.SetForegroundWindow(app_dialog)## doesn't work
Thanks for reading :)
Can't say why it doesn't work with pywinauto...
Got it to work with win32gui as the answer here- Python Window Activation
long yet efficient ;)
Method app_dialog.set_focus() should work in pywinauto 0.6.2. If not, it might be a bug. Is your application publicly available somehow? I'd like to reproduce it on my side. Are you trying to activate a background window while you have modal dialog on top of it?
Second case is a wrong usage of SetForegroundWindow(...). It should give a handle, but you pass WindowSpecification object app_dialog. Right way is the following:
handle = app_dialog.wrapper_object().handle
pywinauto.win32functions.SetForegroundWindow(handle)

Python Pywinauto no control_identifiers or children in application

Hey everyone I'm having a hard time automating a specific application. Using pywinauto I want to automate clicking, keypresses, etc. to login and benchmark this application but for some reason I can't find any control identifiers for this application. Am I doing something wrong? I used this same method with task manager and other applications and this works fine.
Important Documentation:
Code Example
Class Doc
Code:
import pywinauto
app = pywinauto.application.Application()
window_handle = pywinauto.findwindows.find_windows(title = u'Name of application')
#print window_handle #makes sure to see if handle exists
window = app.window_(handle = window_handle[0])
print window.Children() #first approach
print app.top_window_()._ctrl_identifiers() #second approach
Output:
>>>[]
>>>{}
Has this happened to anyone before and has found a way around it? Should I just resort to using pywin32 instead? Thank you!
Turns out the application does have control identifiers I just needed to get past the first screen. Using window.TypeKeys("{TAB}{TAB}{ENTER}") I was able to navigate past the home screen with keypresses and into the actual application which had all the identifiers.
Useful Links if anyone encounters this problem.
What is a control Identifier?

easygui CLOSE button (on top right of window) not functioning

i have created a chat system in python, using easygui for graphical user interface.
there are minimize,maximize and close button on top right of window,but the close button is not functioning at all.i just can use the exit button which i created to close the application. i had some search and found there is a problem with easygui, so is it totally impossible to fix this problem? or how can i remove that close button from top right as there is no use for it. its final year project and i'm afraid my advisor and supervisor want try that button and i lose mark because of no function
is there anyway to fix it or at least remove that close button?
This is likely past the due date for your assignment...sorry. But, that was a known limitation of easygui. An up-to-date version with a fix for that will be released soon. If you can't wait, you can take a look at it in development form: https://github.com/robertlugg/easygui

Categories

Resources