This program can find a browser by its title and close all tabs and prints all the URLs in the proper window.
import time
import pywinauto
from pywinauto import Application
#BrowserTitle will be an array with running instances of browsers.
BrowserTitle = "YouTube - Opera"
app = Application(backend='uia')
app.connect(title=BrowserTitle)
#name of the browser URL box
element_name = "Adresové pole"
dlg = app.top_window()
dlg.click_input()
#url = dlg.child_window(title=element_name, control_type="Edit").get_value()
#print(URL)
#LIST OF TABS
wrapper_list = dlg.descendants(control_type="TabItem")
time.sleep(2)
app.wait_cpu_usage_lower()
for wrapper in wrapper_list:
print(wrapper.window_text())
print(dlg.child_window(title=element_name, control_type="Edit").get_value())
#closing current tab
pywinauto.keyboard.send_keys('^w')
time.sleep(2)
app.wait_cpu_usage_lower()
When all tabs are closed and all URLs are printed, it close the full window that it connects to. Then the main problem raises on line 24 where it doesn't finish properly.
self._element = IUIA().iuia.ElementFromHandle(handle_or_elem)
_ctypes.COMError: (-2147220991, 'An event was unable to invoke any of the subscribers', (None, None, None, 0, None))
Questions?
What does the error mean and how could I deal it with?
Why sometimes happens that on line 23 wrapper.window_text()
doesn't print out the title of the tab.. why? Is it because of the overloaded CPU?