robertsantana Posted September 8, 2022 Posted September 8, 2022 (edited) expandcollapse popup#include<GUIConstants.au3> #include<MsgBoxConstants.au3> #include<File.au3> ShellExecute("https://wwwx.gissonline.com.br/interna/default.cfm") Sleep(500) MouseClick("primary",366,150,1,10) ChecarJanela() Func ChecarJanela() $x = 2 $y = 0 $largura = 614 $altura = 816 Local $pos = WinGetPos("Gissonline - Google Chrome") ;~MsgBox($MB_SYSTEMMODAL, "","X:" & $pos[0] & "Y:" & $pos[1] & "Largura:" & $pos[2] & "Altura:" & $pos[3]) If $pos [0] == $x And $pos [1] == $y And $pos [2] == $largura And $pos [3] == $altura Then Iniciarbot() Else Ajustarjanela($x,$y,$largura,$altura) EndIf EndFunc Func Ajustarjanela ($x,$y,$largura,$altura) WinMove("Gissonline - Google Chrome","",$x,$y,$largura,$altura) ChecarJanela() EndFunc Func Iniciarbot() while 1 ProcurarpixelOnline() WEnd EndFunc Func ProcurarpixelOnline() $tempo = TimerInit() $temporegistrado = 0 while 1 $pixel = PixelSearch(0, 0, 586, 454, 0xFF007F) If Not @error Then ;online If $temporegistrado = 0 Then $Hora = @HOUR & ":" & @MIN & ":" & @SEC $temporegistrado = 1 EndIf $novo = TimerDiff ($tempo) $novo = (1000) + $novo $segundos = Round ($novo/1000) $novoMin = Floor ($segundos/60) $novoSeg = Mod ($segundos,60) If $novoSeg < 10 Then $novoSeg = "0" & $novoSeg $tempoOnline = $novoMin & ":" & $novoSeg EndIf Else ;offline If Not IsDeclared ("Hora") Then $Hora = 0 EndIf Sleep(500) If Not IsDeclared ("tempoOnline") Then ExitLoop Else Local $Arquivo = FileOpen("C:\Users\robert.santana\desktop\" & @MDAY & "-" & @MON & "-" & @YEAR & ".txt",1) FileWrite($Arquivo, "["& $Hora &"] tempo online: " & $tempoOnline & @CRLF) FileClose($Arquivo) ExitLoop EndIf EndIf WEnd EndFunc Hello, I started to study a little about auto and I'm new to the programming area, even a layman. I'm having difficulties in putting together a script, because it's giving an error in this part of the variable, if anyone can help me. I already apologize for the English I'm not fluent teste (321).au3 Edited September 8, 2022 by robertsantana
Dan_555 Posted September 9, 2022 Posted September 9, 2022 (edited) Whenever an array is expected to be created (e.g. out of a function), you should check @error, see the description if this case, it is the WinGetPos("Gissonline - Google Chrome") in which the browser title is probably not found or not active and therefore the array is not created. Because there is no error checking, the function continues as if it is created. This should fix it: Func ChecarJanela() $x = 2 $y = 0 $largura = 614 $altura = 816 Local $pos = WinGetPos("Gissonline - Google Chrome") ;~MsgBox($MB_SYSTEMMODAL, "","X:" & $pos[0] & "Y:" & $pos[1] & "Largura:" & $pos[2] & "Altura:" & $pos[3]) if @error=0 then If $pos [0] == $x And $pos [1] == $y And $pos [2] == $largura And $pos [3] == $altura Then Iniciarbot() Else Ajustarjanela($x,$y,$largura,$altura) EndIf EndIf EndFunc But you should adapt your code to reflect the case that the web browser is not at the wanted page ... Eventually you should, instead of the sleep in the: ShellExecute("https://wwwx.gissonline.com.br/interna/default.cfm") Sleep(500) Replace it with WinWaitActive("Gissonline - Google Chrome") - It could fix it, as well. Edited September 9, 2022 by Dan_555 Some of my script sourcecode
robertsantana Posted September 9, 2022 Author Posted September 9, 2022 4 hours ago, Dan_555 said: Sempre que se espera que um array seja criado (por exemplo, fora de uma função), você deve verificar @error, veja a descrição neste caso, é o WinGetPos("Gissonline - Google Chrome") no qual o título do navegador provavelmente não foi encontrado ou não está ativo e, portanto, o array não é criado. Como não há verificação de erros, a função continua como se tivesse sido criada. Isso deve corrigi-lo: Func ChecarJanela ( ) $x = 2 $y = 0 $largura = 614 $altura = 816 Local $pos = WinGetPos ( "Gissonline - Google Chrome" ) ;~MsgBox($MB_SYSTEMMODAL, "","X:" & $pos[0] & "Y:" & $pos[1] & "Largura:" & $pos[2] & "Altura:" &$pos[3]) if @error = 0 then If $pos [ 0 ] == $x E $pos [ 1 ] == $y E $pos [ 2 ] == $largura E $pos [ 3 ] == $altura Então Iniciarbot ( ) Senão Ajustarjanela ( $x , $y , $largura , $altura ) EndIf EndIf EndFunc Mas você deve adaptar seu código para refletir o caso em que o navegador da web não esteja na página desejada ... Eventualmente você deve, em vez de dormir no: ShellExecute ( "https://wwwx.gissonline.com.br/interna/default.cfm" ) Suspensão ( 500 ) Substitua-o por WinWaitActive("Gissonline - Google Chrome") - também pode corrigi-lo. how does WinWaitActive work? I already tried to use it and as soon as I put the script to run, nothing happens, I even put other titles, but the same thing continued
Solution Dan_555 Posted September 10, 2022 Solution Posted September 10, 2022 (edited) WinwaitActive pauses the script until it finds the Title/Class etc, when it finds it, the script continues. See WinWaitActive Launch this script, then launch Notepad. WinWaitActive("[CLASS:Notepad]", "") Send ("Hi") In your example, try using: WinWaitActive("[TITLE:Gissonline - Google Chrome]") Edited September 10, 2022 by Dan_555 Some of my script sourcecode
robertsantana Posted September 13, 2022 Author Posted September 13, 2022 On 10/09/2022 at 07:59, Dan_555 said: WinwaitActive pausa o script até encontrar o título/classe etc, quando o encontra, o script continua. Veja WinWaitActive Inicie este script e, em seguida, inicie o Bloco de Notas. WinWaitActive ( "[CLASS:Notepad]" , "" ) Enviar ( "Oi" ) No seu exemplo, tente usar: WinWaitActive ( "[TÍTULO:Gissonline - Google Chrome]" ) thanks, it helped a lot.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now