我正在使用 python 进行 Windows 自动化,并尝试右键单击音频文件并选择打开方式菜单项以使用 Windows 媒体播放器播放音频文件。
为此,我正在尝试获取文本坐标,并提供这些文本坐标,我计划按如下方式单击它。
import pywinauto
import SendKeys
# getting instance of previously opened window
app = pywinauto.application.Application().window_(title = "My Documents").Wait('visible', timeout=20, retry_interval=0.5)
# focus the existing window
app.SetFocus()
# get the co-ordinates of "audio.mp3"
app.RightClickInput(coords = (x,y))
# get the co-ordinates of "Open with"
app.ClickInput(coords = (x1,y1))
# get the co-ordinates of "Windows Media Player"
app.ClickInput(coords = (x2, y2))
那么,如何获取屏幕上显示的特定文本坐标?
或
我们是否可以仅通过 pywinauto 来完成此操作,而不是获取坐标并点击它们?
最佳答案
有一种更简单的方法可以在不使用 pywinauto 或任何其他 GUI 自动化的情况下完成此类操作。 Windows Media Player 具有可用于打开特定文件的命令行参数。
MSDN article描述了您可能需要的以下参数:
"path\filename"
(For example: wmplayer "c:\filename.wma")
通过使用 subprocess.Popen('wmplayer "c:\filename.wma"')
调用,可以轻松在纯 Python 中运行。
关于python - 使用 python 获取屏幕上文本的 x , y 坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36716741/