打印Google Chrome的控件标识符

dldeef67  于 2023-02-27  发布在  Go
关注(0)|答案(1)|浏览(176)

预期行为

打印Google Chrome浏览器的控件标识符时遇到问题。我已经在命令提示符中输入了--force-renderer-accessibility命令并重新启动了Chrome浏览器。

实际行为

Traceback (most recent call last):
  File "C:\Users\asdffff\AppData\Roaming\Python\Python39\site-packages\pywinauto\timings.py", line 436, in wait_until_passes
    func_val = func(*args, **kwargs)
  File "C:\Users\asdffff\AppData\Roaming\Python\Python39\site-packages\pywinauto\findwindows.py", line 87, in find_element
    raise ElementNotFoundError(kwargs)
pywinauto.findwindows.ElementNotFoundError: {'title': 'New Tab - Google Chrome', 'backend': 'uia', 'visible_only': False}

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\Users\asdffff\OneDrive n1ck99\OneDrive\Documents\python\pywinauto\github.Chrome2.py", line 4, in <module>
    app = Application(backend="uia").connect(title='New Tab - Google Chrome',timeout=5)
  File "C:\Users\asdffff\AppData\Roaming\Python\Python39\site-packages\pywinauto\application.py", line 990, in connect
    self.process = timings.wait_until_passes(
  File "C:\Users\asdffff\AppData\Roaming\Python\Python39\site-packages\pywinauto\timings.py", line 458, in wait_until_passes
    raise err
pywinauto.timings.TimeoutError

示例代码

from pywinauto.application import Application
app = Application(backend="uia").start(r"C:\Program Files\Google\Chrome\Application\chrome.exe")
app = Application(backend="uia").connect(title='New Tab - Google Chrome',timeout=5)
app.NewTabGoogleChrome.print_control_identifiers()
fcg9iug3

fcg9iug31#

嗨,我也面临着类似的问题,并发现,对于Chrome更改后端到win32

"""Start and connect application"""
app3 = Application(backend="win32")\
        .start("C:\Program Files\Google\Chrome\Application\chrome.exe")\
        .connect(title=u'Google Chrome')

app3.GoogleChrome.print_control_identifiers()

输出:

Control Identifiers:

Chrome_WidgetWin_1 - 'Google Chrome'    (L175, T9, R1744, B999)
['Chrome_WidgetWin_1', 'Google ChromeChrome_WidgetWin_1', 'Google Chrome']  
child_window(title="Google Chrome", class_name="Chrome_WidgetWin_1")        
   |
   | Chrome_RenderWidgetHostHWND - 'Chrome Legacy Window'    (L186, T54, R1734, B989)
   | ['Chrome Legacy WindowChrome_RenderWidgetHostHWND', 'Chrome_RenderWidgetHostHWND', 'Chrome Legacy Window']
   | child_window(title="Chrome Legacy Window", class_name="Chrome_RenderWidgetHostHWND")
   |
   | Intermediate D3D Window - ''    (L186, T54, R1733, B988)
   | ['Google ChromeIntermediate D3D Window', 'Intermediate D3D Window']    
   | child_window(class_name="Intermediate D3D Window")

相关问题