I am working with Pywinauto to automate a Desktop Application.
At one point there could be a popup window. With findbestmatch I want to check if the popup is available. The name of the popup window is the same as of the normal window.
Is there an alternative for findbestmatch or is it the best option?
There is a pywinauto function called popup_window() which could be a good starting point for you. See link
Its listed under pywinauto.controls.hwndwrapper, which provides basic wrapping of windows controls. It will return the handle/id of any open popups or a reference to self if no popups exist.
Related
How can I can a function and create a function for the icon context menu? I want to make the iconic Open New Window function pop-up when you right click on the icon menu in the taskbar/dock. See this question for more info on this kind of question.
Places I have looked but found nothing:
https://www.tcl.tk/man/tcl8.5/TkCmd/tk_mac.html#M15
https://pyinstaller.org/en/stable/feature-notes.html#open-event-handling-in-a-tkinter-based-gui-application
While there are a tiny subset of apple events that you can benefit from the DockMenu is not accessible directly via tkinter. Turns out mac is not really open for modifications and even smaller tasks can be hard. You could consider to use a system tray icon instead.
I was trying to handle a browser dialog with Playwright for Python in Firefox (in this case, but I guess the browser does not matter), i.e. a dialog that was opened by Firefox to ask whether to open or save a file. The dialog pops up after I click a button. The link to the file is not exposed, so I cannot download it in another way.
I tried catching a dialog event:
with page.expect_event("dialog") as page_info:
button = page.querySelector('button[id=\"download\"]')
button.click()
which times out. I then thought I found the solution in this GitHub ticket. However, the following did not work either:
page.on("dialog", lambda dialog: dialog.accept())
page.click("button")
Do these kinds of dialog - in contrast to dialogs e.g. raised by JavaScript alert() - not trigger a dialog event? I think they may not, judging by the answers to this post: Is it possible to catch browser's File Open/Save dialog event using Javascript.
If so, how can I accept or dismiss such a dialog using python-playwright?
So, it seems that this is simply not directly possible with python-playwright, nor is it going to be. From this discussion, I gathered that the dialog...
"[...] is not a part of the web, it is a part of the browser, so we don't automate it."
There are workarounds, e.g. to trigger a download in a different way, but this would then not involve handling the browser dialog, as stated in the question.
Try this:
page.once("dialog", lambda dialog: dialog.accept())
On the pywinauto documentation it says that you can click a radio button using the click method:
I have already had issues using the UIA backend, since it is different to win32. In this case, there seems to be no way to click a radio button.
I tried using a window specification:
spec.window(auto_id='RadioButtonManualbackground').click()
AttributeError: Neither GUI element (wrapper) nor wrapper method 'click' were found (typo?)
It cannot find any method called click. I tried using toggle and check and those didn't work either.
I also tried clicking the radio button using the tree hierarchy:
app.Dialog.Analysis.BackgroundCorrection.ManualBackgroundCorrection.click()
pywinauto.uia_defines.NoPatternInterfaceError
Again, this didn't work with toggle or check.
Is there support for clicking a radio button using UIA backend, and how do I do it?
This might be a bit confusing, but radio button wrapper has .select() method which uses SelectionItemPattern. I've found it in test_radio_button unit test.
Proper implementation should check all possible patterns and choose the working one. So I would consider it as a bug: filed issue #549. Thanks for reporting it!
P.S. You always have method .click_input() as a workaround. It performs the most realistic click with moving the cursor.
How to get the right click context menu in a Windows application using Python, do not set the position of the cursor and when not focus that Windows application.
Context menu is not the Explorer context menu, it is the Windows application right click context menu.
Here is an example for Notepad:
app.UntitledNotepad.Edit.Click(button='right') # works
app.PopupMenu.MenuSelect('Paste') # seems not working when Notepad is not in focus
# though it works when app.UntitledNotepad.SetFocus() is called before
app.PopupMenu.MenuSelect('Paste') may not work in such a case because probably WM_COMMAND can be sent to a focused window only. To get it to work use app.PopupMenu.MenuItem('Paste').ClickInput() though your app window will get to focus any way.
So finally there are 2 working examples. The first is:
app.UntitledNotepad.SetFocus()
app.UntitledNotepad.Edit.Click(button='right')
app.PopupMenu.MenuSelect('Paste')
The second is:
app.UntitledNotepad.Edit.Click(button='right')
app.PopupMenu.MenuItem('Paste').ClickInput()
I want to make a click through window. A window which I click but the click pass to the window below it.
I've found this two solutions for windows:
How to make click-through windows PyQt
I have a form that can "click through", i.e. direct clicks to the window below. How can I undo my changes after the event?
But I want it to work in linux. I study the xlib mechanisms but cannot understand how the window stack works. Actually I can get all the windows with XQueryTree() and found the ones under my window. But I don't know witch one are above.