简体   繁体   中英

How to bring a popup window to the foreground in Python

I have been trying to automate a browser login. As part of login I get a pre-auth pop-up (which is not a browser pop-up nor a native windows pop-up). I have to allow the pop to scan my computer so that I could get to the login page. However I am not able to bring the pop-up window to foreground for further processing.

Things I have tried so far:

  1. Try to use selenium alert function (by this I came to know it is not a browser pop-up). I also tried to get the open handles for all the browser windows (using function window_handle(), I only get one handle that is for the main browser window).

  2. I tried to find all of the open windows on the system using the code below and I get a list of windows handles along with window title, but the window I am looking for does not have a window title.

Code to find titles and hwnd of all the visible windows:

def get_all_windows():
    """Returns dict with window desc and hwnd,
    don't ask me how it works!"""

    def _MyCallback( hwnd, extra ):
        """Helper function for above??"""
        hwnds, classes = extra
        hwnds.append(hwnd)
        classes[win32gui.GetWindowText(hwnd)] = hwnd

    windows = []
    classes = {}
    win32gui.EnumWindows(_MyCallback, (windows, classes))
    return classes

Please give me comments on how I should be taking this thing forward. I have been trying this through the weekend without luck.

Normally authentication popups can be handled with keyboard events. In java bindings you can use Java Robot classes to simulate keyboard events. In high level your steps will be like this.

  1. Type user name
  2. Press Tab to go to the password field
  3. Type password
  4. Press Tab to get focus on Ok button
  5. Press Enter

Please refer the following answer for performing keyboard events in Python.

generate-keyboard-events in Python

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM