Search code examples
pythonregexgoogle-chromepywinauto

Why the Regular Expression didn't work well in Pywinauto


from pywinauto import application

app=application.Application()
3. app.connect(title_re = "/Zero Hedge$/")
4. app.connect(title_re = "/| Zero Hedge/")

I want to get a window of Chrome like this: http://www.zerohedge.com/news/2016-02-18/markets-ignore-fundamentals-and-chase-headlines-because-they-are-dying

As you see when you visit the website, the website title contains "| Zero Hedge" in the last part of it or only "Zero Hedge" contained.

However, I still get a WindowNotFoundError raised in no matter line 3 or line 4. Why the Regular Expression didn't work?

Thank you for all your help!


Solution

  • try this to get a list of all of your windows/titles:

    from pywinauto import findwindows
    
    print findwindows.find_windows(title_re=".*")
    

    That should get you a list of all windows and then build your regex based off the results.