0

Goal: I want to retrieve with Python the IE instance that is running on my computer in order to listen to all click events inside the HTML Document.

Python interpreter: 3.7

My Solution: In order to retrieve the IE instance, I thought that one solution would be by means of the PID. Once I have the IE instance, I could create an event listener with this object and see where user has clicked and record the information of the button or element that was clicked.

For that reason, what I did so far was to retrieve the HWND of the current IE instance that is located on the foreground by means of Pyhook library. With this HWND and win32process I got the Process ID (PID).

Is there a better approach to do that?. Thanks for your help in advance

Current code:

Getting the pid of a particular HWND

tid,pid = win32process.GetWindowThreadProcessId(hwnd)

With Pyhook I can retrieve the HWND with Window property

hwnd = event.Window
sergioMoreno
  • 189
  • 1
  • 15
  • 1
    From your description, it seems that you want to do some automated test in IE browser, unfortunately, I'm not finding a related resource to use python to retrieve the IE instance, but you could consider to use a VBA script or C# method to retrieve the IE instance, please refer to the following articles: [Link1](https://stackoverflow.com/questions/21837844/vba-code-to-interact-with-specific-ie-window-that-is-already-open) and [link2](https://social.msdn.microsoft.com/Forums/vstudio/en-US/ca257f22-115e-43f2-a28d-c806c81061b7/get-url-of-ie-firefox-and-chrome-brower) – Zhi Lv Mar 06 '20 at 07:38
  • Hi @ZhiLv-MSFT thanks for your help. Do you know maybe how can I get IE instance by means of its PID en C# or VBA?. I am using comtypes and I could use the same method in theory. The problem is when there more instances opened, I thought that the best way is with its respective PID. – sergioMoreno Mar 06 '20 at 12:31
  • There has a [Process Class](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process?view=netframework-4.8), which contains the GetProcessesByName or GetProcessById method, they will help to find the IE process. If you want to find the special window according to the web page url or title, you could check [this thread](https://stackoverflow.com/questions/8445742/). – Zhi Lv Mar 09 '20 at 09:10
  • For VBA method to find the IE window, please check this articles: [Link1](https://stackoverflow.com/questions/53176415/retrieving-a-url-from-internet-explorer-with-vba) and [Link2](https://excel-macro.tutorialhorizon.com/vba-excel-get-all-the-opened-internet-explorer-ie-using-microsoft-excel/). – Zhi Lv Mar 09 '20 at 09:10

0 Answers0