如何使用c#在屏幕上查找文本并获取其坐标



我想自动化安装在我的机器上的软件。我正在使用AutoIt,但在一个屏幕上,我无法获得控件ID或标题,因此我可以访问该控件,然后在其中查找文本。我想点击那个文本,所以我需要那个文本的坐标。我如何使用c#代码或任何其他第三方工具来协调文本?我在谷歌上查过,但找不到任何有趣或有用的东西。任何与这个问题有关的事情都将不胜感激。

正如其他人所说,你问的问题有点模糊。你想自动化什么样的软件?您希望更精确地自动化什么?(鼠标动作?点击?软件上的特殊内容?…)

例如,关于鼠标点击,有两种主要方法可以使过程自动化:基于屏幕坐标的单击或基于窗口坐标的单击。下面,您可以找到一个自动安装特定应用程序的示例从"web平台安装程序5.0"(您可以从Microsoft网站@下载https://azure.microsoft.com/en-us/tools/-->视觉工作室2015)

;Gives Admin rights to autoIT
#RequireAdmin
;launches the program in the same directory as the installer
Run(@ScriptDir & 'azure.exe')
;Sets the coordinates as window coordinates with "0" (VS screen coordinates) 
AutoItSetOption('MouseCoordMode',0)
;Waits for the program to open and to display a text like "Microsoft Web Platform Installer"
WinWait("Web Platform Installer 5.0","Microsoft Web Platform Installer")
;wait 1.5 seconds
sleep(1500)
;When the window is visible, le cursor is set as active ont that window (IMPORTANT)
WinActivate("Web Platform Installer 5.0")
;the following commands are mouseclicks on specific boxes of the program to automate specific installs on the installer
;MouseClick('primary', x, y, 1, speed (1 to 10))
; You will find those coordinates in the "AU3info.exe file" after you've installed autoIT ( Au3info allows to find coordinates
; by targeting specific places on a window)
MouseClick('primary', 155, 60, 1, 10)
sleep(1500)
;selects 4 apps to be installed (4 installs), clics INSTALL and waits 1.5 sec
MouseClick('primary', 817, 122, 1, 10)
MouseClick('primary', 821, 163, 1, 10)
MouseClick('primary', 815, 401, 1, 10)
MouseClick('primary', 828, 519, 1, 10)
MouseClick('primary', 692, 587, 1, 10)
sleep(1500)
;Prepaing the install and waiting till a text like "Review the following list" apprears
WinWait("Web Platform Installer 5.0","Review the following list")
WinActivate("Web Platform Installer 5.0")
sleep(1500)
MouseClick('primary', 43, 350, 1, 10)
MouseClick('primary', 603, 433, 1, 10)
;starts the installation and waits till the installation is finished (when "The following"..programm has installed ..blabla
WinWait("Web Platform Installer 5.0","The following")
MouseClick('primary', 612, 434, 1, 2)
;gets rid of some issues stemming from microsoft edge (the send functions allows to send keyboard keys (like ESC, SPACE, ALT, etc..))
sleep(1000)
Send("{ENTER}")
MouseClick('primary', 612, 434, 1, 2)
sleep(1000)
Send("{ENTER}")
;quits all the windows with ALT + F4
WinWait("Web Platform Installer 5.0")
WinActivate("Web Platform Installer 5.0")
Sleep(1000)
Send("{ALT down}{F4 down}{F4 up}{ALT up}")
Sleep(1000)
Send("{ALT down}{F4 down}{F4 up}{ALT up}")

相关内容

  • 没有找到相关文章

最新更新