Hi! I'm having a particular problem using FindText() and for the life of me, I can't wrap my head around what's going on.
I'm using FindText to automate posting to a certain site with a modified WordPress backend. I use it to find the fields I need to fill, and some tabs and buttons to press.
There are two similar features in this system that I use, that
should let me reuse some of my code. You can set a featured image for the post, or insert an inline image in the middle of it. Both of these functions are called through different buttons, but once you click them, you are presented with essentially the same thing: two tabs for browsing your computer or select an already uploaded image, and when you click the first tab, a button for uploading a file.
So, to automate this workflow, I wrote:
(1) a function that clicks the "Upload" tab, then the "Select file" button;
(2) a function to set the featured image, that clicks the "Set featured image" button, then calls function 1;
(3) a function to insert an inline image, that clicks the "Add object" button, then calls function 1.
The problem I'm having is that function 1 NEVER finds the "Select file" button when called from function 3. It ALWAYS works when called from function 2. And it should work every time -- the button it just the same. I know it's the same because I ran FindText on it, replaced the text I had before, and it's still working for function 1, but failing for function 2.
I don't know what's going on, so I thought I'd ask here.
I'm using this code:
(function 1)
Code: Select all
SubirArchivo( arch ) {
SubirArchivosTab := "|<Subir archivos>*196$106.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000810000040U00000DU0U400000E200000120200000010000000A00800000040000000k48j4S1sySLWknkS01UEX6HU8n39W92Mm803V28N403AM4AYP38003Y8UYk1wl0EmN84s006EW2F0AH4138YkEs00/28N40VAM4AWn31U0VaMl4E2AkmEm66M603wCXsF0Dm1t38MD3k0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000U"
if (ok:=FindText(0, 0, A_ScreenWidth, A_ScreenHeight, 0, 0, SubirArchivosTab))
{
CoordMode, Mouse
X:=ok.1.1, Y:=ok.1.2, W:=ok.1.3, H:=ok.1.4, Comment:=ok.1.5, X+=W//2, Y+=H//2
Click, %X%, %Y%
}
Sleep 666
SelArchButton := "|<Selecciona archivos>*159$133.00000000000000000000000000000000000000000000000800030000000010M0000w040001U00000000UA0001U020000000000000E00000U010000000000000800000M1sVsSDgS7sS0S/7Ztg8wD616F6MA6Mn6FUFa4H4m4l41lV9VM4289V0k0G412N6kq0AzYzc61g4lXs3t20VAmE9U2E2E430o2MGA34V0Ea984A1g1A30UN1A/412EU8H5663EW0W4kMAla5b0X8MY9VVW1jUwEwD7aD32R0TY3m4kkSDU0000000000000000000004"
if (pk:=FindText(0, 0, A_ScreenWidth, A_ScreenHeight, 0, 0, SelArchButton))
{
CoordMode, Mouse
X:=pk.1.1, Y:=pk.1.2, W:=pk.1.3, H:=pk.1.4, Comment:=pk.1.5, X+=W//2, Y+=H//2
Click, %X%, %Y%
WinWait, Open, , 2
Sleep 1111
Clip( arch ) ; this sends the filename
Send {Enter}
}
}
(function 2)
Code: Select all
EstablecerImagenDestacada( foto ) {
Send {Home}
Sleep 333
Send {PgDn}
Sleep 333
Text := "|<Establecer imagen destacada>*196$133."
. "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010800001U00000000A00000U400000000000000600400E200000000000000300200/X7Vlsw4ysS7ksy0TXlnnkq8aF1aE2Na9aMWNU8m9UU8m6G50V818F0G4l8E8N2kE6F29yUTY0a8Xt2Tq84AzC8T8VgUE820HAH4V82426E1YFYMWEA6109296NW1W1XA4G8nDV7XlwU4n4T7Ewl0TXnknsk000000000008000000000000000000000A000000000000000000001w000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004"
if (ok:=FindText(0, 0, A_ScreenWidth, A_ScreenHeight, 0, 0, Text))
{
CoordMode, Mouse
X:=ok.1.1, Y:=ok.1.2, W:=ok.1.3, H:=ok.1.4, Comment:=ok.1.5, X+=W//2, Y+=H//2
Click, %X%, %Y%
}
Sleep 666
SubirArchivo( foto )
}
(function 3)
Code: Select all
AñadirObjeto( objeto ) {
AñadirObjetoButton := "|<Añadir objeto>*172$131.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000y000000000000000000003w00000000000000000000Tz00000000000000000000zy00000000000000000001sy00000000000000000003Utw043000a000k400000071vk0Q5U010001U00M0000T7rk0c00020003000k0000Tz1U1Mi7VwHkD7sXnls000zy304la94Na0nCNAn68001zw608W438H8128GEa8E00000A0za8yEWE66kYzAkU0000ks118GAV4U49V90MV00007Xk22MYNaN0AF6F0la0000TD0A6lDlom0D7sXsls0000wy00000000000100000001sw00000000000600000001Vk00000000000M000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004"
if (ok:=FindText(0, 0, A_ScreenWidth, A_ScreenHeight, 0, 0, AñadirObjetoButton))
{
CoordMode, Mouse
X:=ok.1.1, Y:=ok.1.2, W:=ok.1.3, H:=ok.1.4, Comment:=ok.1.5, X+=W//2, Y+=H//2
Click, %X%, %Y%
Sleep 333
SubirArchivo( objeto )
}
}