Unfortunately Pywinauto cannot retrieve the information you wish to have. Indeed Pywinauto identifies only few elements of this GUI.
But your idea "right_click->select all then right_click->copy" is a possible way to do it. You just have to identify the region to copy. You can do it with Pywinauto. Here is the code generated by Pywinauto_recorder to reach the data you want to retrieve with some little enhancements:
# encoding: utf-8
import pyperclip
import os, sys
script_dir = os.path.dirname(__file__)
sys.path.append(script_dir)
from pywinauto_recorder.player import *
PlayerSettings.mouse_move_duration = 0
with Window(u"Highlighted Params:Bottle0.OUT||Window"):
right_click(u"stcwindow||Pane")
with Window(u"Context||Menu"):
left_click(u"Select All||MenuItem")
with Window(u"Highlighted Params:Bottle0.OUT||Window"):
right_click(u"stcwindow||Pane")
with Window(u"Context||Menu"):
left_click(u"Copy||MenuItem")
result = pyperclip.paste()
print(result)
I made the following modifications:
- I added PlayerSettings.mouse_move_duration = 0 to eliminate intermediate mouse movements
- I removed the relative coordinates inside the searched element (percentage inside the detected element from the edges) because you don't need them.
With Nothing or %(0,0) to click in the centre of the element, with %(-100.0) it will click in the centre of the left edge of the element, with
%(100.0) it will click in the centre of the right edge of the element
etc...
- I added two lines that use pyperclip.paste() to print the result
Pywinauto_recorder identifies elements in the same way as Pywinauto and also allows a list of elements to be disambiguated using various strategies.
In your case there is no problem to uniquely identify DeltaEC elements (even if few elements are accessible, all areas hovered over by the mouse are coloured green).
To uniquely identify an element Pywinauto_recorder constructs a path based on the names and types of the parent elements of the searched element. It starts with the highest level parent element, then its descendant and continues in the hierarchy until reaching the searched element.
# encoding: utf-8
import os, sys
script_dir = os.path.dirname(__file__)
sys.path.append(script_dir)
from pywinauto_recorder.player import *
with Window(u"Highlighted Params:Bottle0.OUT||Window"):
left_click(u"stcwindow||Pane")
right_click(u"stcwindow||Pane")
with Window(u"Context||Menu"):
wrapper = move(u"Select All||MenuItem")
wrapper.draw_outline()
print(wrapper.window_text())
I made the following modifications:
- I removed the relative coordinates (percentage inside the detected element) because you don't need them.
- I added two lines that use the Pywinauto functions 'draw_outline()' and 'window_text()'.
Some elements appear dynamically. This is the case for menu items. Note that to access the 'Select All' item, I call the 'move' function instead of 'left_click' so as not to close the menu.
The previous code works only with the input file 'Bottle0.OUT' if you want to make it work with all input files:
# encoding: utf-8
import os, sys
script_dir = os.path.dirname(__file__)
sys.path.append(script_dir)
from pywinauto_recorder.player import *
with Window(u"Highlighted Params:.*||Window", regex_title=True):
left_click(u"stcwindow||Pane")
right_click(u"stcwindow||Pane")
with Window(u"Context||Menu"):
wrapper = move(u"Select All||MenuItem")
wrapper.draw_outline()
print(wrapper.window_text())
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…