Neophito Posted February 1, 2022 Posted February 1, 2022 It only interacts with the web page if it is monitoring. Hi. I'm a 60 year old man with little programming knowledge, but as I need a solution, I decided to try to develop an automation using Autoit. I'll try to be as objective as possible, but I apologize because I don't know English well (Googje translator helps me) I developed a script to be launched by the Windows 10 task scheduler. The scheduler always runs the compiled no problem. But when calling a Chrome page it only interacted if I'm seeing it. If not monitoring it hangs on the open page. I'm using the Danp2 master's Webdriver UDF and the version of SciTE and other UDFs are the latest. Chromedriver starts successfully. Believe me my script is very simple. My intention is just to interact with a web page. Thanks.
Nine Posted February 1, 2022 Posted February 1, 2022 It would greatly help if you can share your script. Try also to select a web page that we can access in order for us to try to reproduce your issue. BTW welcome to AutoIt forum. SOLVE-SMART and Danp2 2 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Neophito Posted February 1, 2022 Author Posted February 1, 2022 Thank you Nine. I will provide a more "secret" post, but with the exception of my problem for your observation.
Neophito Posted February 4, 2022 Author Posted February 4, 2022 expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=curinga.ico #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <MsgBoxConstants.au3> #include <FileConstants.au3> #include <WinAPIFiles.au3> #include <Date.au3> #include <GUIConstantsEx.au3> #include <color.au3> #include <ColorConstants.au3> #include <WindowsConstants.au3> #include <WinAPISysWin.au3> #include <WinAPIError.au3> #include <AutoitConstants.au3> #include <Chrome.au3> #include "wd_core.au3" #include "wd_helper.au3" ; ############## ; # # ; # 03 FEV 22 # ; # # ; ############## Global $cronometro = 90 ;tempo em segundos utilizado no cronômetro regressivo. Global $adicional = 0 ;minutos aleatórios para aguardar antes de fechar o expediente. Global $entrada = 0 ;horário em minutos da entrada pela manhã. Global $saida = 0 ;horário em minutos da saída para almoço. Global $retorno = 0 ;horário em minutos do retorno após o almoço para o período 3 Local $fim = 0 ;horário em minutos para encerrramento do expediente Local $dezoito = 0 ;total trabalhado até às 18 horas If @HOUR = 8 Then ;Como o início sempre se dará às 8 horas, apenas agora todas (não calculadas) as variáveis são zeradas $entrada = 0 $saida = 0 $retorno = 0 $fim = 0 EndIf Run ("notepad.exe c:\registro\agenda.txt") $arquivo = FileOpen ("c:\registro\agenda.txt", 1) ; , 1 = modo escrita - Adiciona ao final do arquivo FileWrite($arquivo, " Agora são: " & _NowTime() & " do dia " & _NowDate() & @LF) Sleep (2000) WinClose("[CLASS:Notepad]", "") $argumento = 1 Local $i = 1 While $i <= $CmdLine[0] ; A variável $CmdLine[0] retorna a quantidade de argumentos passados e o laço While faz a varredura MsgBox($MB_SYSTEMMODAL, "Argumentos = " & $CmdLine[0], "O valor do " & $i & "o. " & "argumento é " & $CmdLine[$i], 5) ; Decide se o argumento passado é de um dia a ser desconsiderado, se for encerra o programa senão segue para a ação If @MDAY = $CmdLine[$i] Then MsgBox($MB_SYSTEMMODAL, "Dia Atual", "Hoje é dia: " & @MDAY, 5) ;Mostra o número do dia atual sleep(2000) MsgBox($MB_SYSTEMMODAL, "Decisão", "Hoje não tem expediente", 5) Exit EndIf $i = $i + 1 WEnd ; ***************************************************************************** ; *****************************************************2************************ Local $Espera = 0 $Espera = Random(0,$cronometro,1) ; de forma aleatória (randômica) gera um intervalo de tempo entre 0 e 15 minutos = 900 segundos **************************************************************************** **************************************************************************** MsgBox($MB_SYSTEMMODAL, "AGUARDANDO", "O aplicativo vai aguardar: " & $Espera & " segundos", 5) ######################################################################################################### ; Standby ######################################################################################################## $Espera *= 1000 ;O algoritmo opera com milisegundos por isso multiplica-se por 1000. Global $SS_CENTER, $_Minutes, $_Seconds $_GuiCountDown = GUICreate ( "ESPERA...", 156, 80, @DesktopWidth -160, @DesktopHeight -124, $WS_EX_TOPMOST ) GUISetBkColor ( 0x0000FF ) $TimeLabel = GUICtrlCreateLabel ( "", 20, -4, 240, 50 ) GUICtrlSetColor(-1, $COLOR_WHITE) GUICtrlSetFont (-1, 36, 600, -1, "digiface" ) GUISetState ( ) WinSetOnTop ( $_GuiCountDown, "", 1 ) $TimeTicks = TimerInit ( ) $condicao = 1 While $condicao <> 0 _Check ( ) Sleep ( 200 ) WEnd Func _Check ( ) $Espera -= TimerDiff ( $TimeTicks ) $TimeTicks = TimerInit ( ) Local $_MinCalc = Int ( $Espera / ( 60 * 1000 ) ), $_SecCalc = $Espera - ( $_MinCalc * 60 * 1000 ) $_SecCalc = Int ( $_SecCalc / 1000 ) If $_MinCalc <= 0 And $_SecCalc <= 0 Then GUISetBkColor ( 0x000000, $_GuiCountDown ) GUICtrlSetFont (-1, 36, 600, -1, "digiface" ) GUICtrlSetColor(-1, $COLOR_YELLOW) GUICtrlSetData ( $TimeLabel, " FIM!" ) Sleep ( 1000 ) GUIDelete() $condicao = 0 Else If $_MinCalc <> $_Minutes Or $_SecCalc <> $_Seconds Then $_Minutes = $_MinCalc $_Seconds = $_SecCalc GUICtrlSetData ( $TimeLabel, StringFormat ( "%02u" & ":" & "%02u", $_Minutes, $_Seconds ) ) If $_Minutes = 0 And $_Seconds <= 3 Then Beep ( 440, 300 ) GUISetBkColor ( 0xA093FF, $_GuiCountDown ) EndIf EndIf EndIf EndFunc ;==> _Check ( ) If @HOUR <> 18 Then Run ("notepad.exe c:\registro\agenda.txt") $arquivo = FileOpen ("c:\registro\agenda.txt", 1) ; , 1 = modo escrita - Adiciona ao final do arquivo FileWrite($arquivo, " Agora são: " & _NowTime() & " do dia " & _NowDate() & @LF) Sleep (2000) WinClose("[CLASS:Notepad]", "") EndIf Func minutos() $minutos = 0 $horas2minutos = 0 $horas2minutos = @HOUR * 60 $minutos = $horas2minutos + @MIN Return $minutos EndFunc Func Guardar($recebe) SELECT Case $recebe = $entrada $VARIAVEL = "ENTRADA" Sleep(2000) IniWrite("C:\REGISTRO\Valores.ini", "GRAVADA", "ENTRADA", $recebe) Case $recebe = $saida $VARIAVEL = "SAIDA" Sleep(2000) IniWrite("C:\REGISTRO\Valores.ini", "GRAVADA", "SAIDA", $recebe) Case $recebe = $retorno $VARIAVEL = "RETORNO" Sleep(2000) IniWrite("C:\REGISTRO\Valores.ini", "GRAVADA", "RETORNO", $recebe) EndSelect EndFunc ; Fecha a função Guardar() Sleep(2000) Select Case (@HOUR = 8) Or (@HOUR = 9) $entrada = minutos() MsgBox($MB_SYSTEMMODAL, "REGISTRADO", "Valor a ser guardado n arquivo valores.ini - ENTRADA = " & $entrada, 5) Guardar($entrada) Case @HOUR = 12 $saida = minutos() MsgBox($MB_SYSTEMMODAL, "REGISTRADO", "Valor a ser guardado n arquivo valores.ini - SAIDA = " & $saida, 5) Guardar($saida) Case @HOUR = 13 $retorno = minutos() MsgBox($MB_SYSTEMMODAL, "REGISTRADO", "Valor a ser guardado n arquivo valores.ini - RETORNO = " & $retorno, 5) Guardar($retorno) EndSelect If @HOUR = 18 Then $entrada = iniRead("valores.ini", "GRAVADA", "ENTRADA", "Ocorreu uma falha!") MsgBox($MB_SYSTEMMODAL, "RECUPEROU", "Valor recuperado do valores.ini - ENTRADA = " & $entrada, 5) $saida = IniRead("valores.ini", "GRAVADA", "SAIDA", "Ocorreu um problema!") MsgBox($MB_SYSTEMMODAL, "RECUPEROU", "Valor recuperado do valores.ini - SAIDA = " & $saida, 5) $retorno = IniRead("valores.ini", "GRAVADA", "RETORNO", "Algo deu errado!") MsgBox($MB_SYSTEMMODAL, "RECUPEROU", "Valor recuperado do valores.ini - RETORNO = " & $retorno, 5) Sleep(2000) $dezoito = (1080 - $retorno) + ($saida - $entrada) ;1080 = 18 horas * 60 minutos. MsgBox($MB_SYSTEMMODAL, "CONFERINDO", "Pela manhã = " & ($saida - $entrada) & " e a tarde = " & (1080 - $retorno) & " minutos", 5) $fim = (480 - $dezoito) ;Diferença do que falta para 8 horas de trabalho. MsgBox($MB_SYSTEMMODAL, "AGUARDANDO", "Minutos que faltam para 8 horas: " & $fim, 5) Sleep(2000) $adicional = ($fim*60) $adicional *= 1000 ;O algoritmo opera com milisegundos por isso multiplica-se por 1000. Sleep(2000) $Espera = $adicional ;necessário porque a função _Check() utilizada a variável $Espera Sleep(2000) Global $SS_CENTER, $_Minutes, $_Seconds $_GuiCountDown = GUICreate ( "RESTANDO...", 156, 80, @DesktopWidth -160, @DesktopHeight -124, $WS_EX_TOPMOST ) GUISetBkColor ( 0x0000FF ) $TimeLabel = GUICtrlCreateLabel ( "", 20, -4, 240, 50 ) GUICtrlSetColor(-1, $COLOR_WHITE) GUICtrlSetFont (-1, 36, 600, -1, "digiface" ) GUISetState ( ) WinSetOnTop ( $_GuiCountDown, "", 1 ) $TimeTicks = TimerInit ( ) $condicao = 1 Sleep(2000) While $condicao <> 0 _Check ( ) Sleep ( 200 ) WEnd Run ("notepad.exe c:\registro\agenda.txt") $arquivo = FileOpen ("c:\registro\agenda.txt", 1) ; , 1 = modo escrita - Adiciona ao final do arquivo FileWrite($arquivo, " Pela manhã = " & ($saida - $entrada) & " minutos e a tarde mais " & (minutos() - $retorno) & " minutos." & @LF) FileWrite($arquivo, " Agora são: " & _NowTime() & " do dia " & _NowDate() & @LF) Sleep(2000) $alem = (480 - (($saida - $entrada) + (minutos() - $retorno))) Sleep(2000) FileWrite($arquivo, " O expediente total foi de 8 horas e " & $alem & " minutos." & @CRLF & @LF) Sleep (2000) WinClose("[CLASS:Notepad]", "") EndIf ; ###################################################################################### Sleep(2000) Local $sDesiredCapabilities, $sSession _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "http://intranet.ufpr.br/frequencia.html") Sleep(2000) _WD_Alert($sSession, 'accept') Func SetupChrome() _WD_Option('Driver', 'c:\REGISTRO\chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["start-maximized","disable-infobars"]}}}}' EndFunc ;==>SetupChrome $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"browserName": "chrome", "acceptInsecureCerts":true}}}' Sleep(2000) Send("!{ESCAPE}") Sleep(2000) _ChromeStartup("-kiosk http://www.intranet.ufpr.br/frequencia/","C:\Arquivos de Programas\Google\Chrome\Application\chrome.exe") Sleep(2000) $sCommand = "ACTIONS" _WD_Action($sSession, $sCommand) Sleep(2000) ;User: wenzel; Password: Vftna21* Send("{TAB}") Sleep(2000) Send("{TAB}") Sleep(2000) Send("{ENTER}") Sleep(3000) $hora = @HOUR MsgBox($MB_SYSTEMMODAL, "AGORA", "Hora para escolher se entra ou sai: " & $hora, 5) Sleep(2000) #cs if ($hora = 12) Or ($hora = 18) Then MouseMove(800, 650,10) ; BOTÃO DE SAÍDA Sleep(2000) MouseClick("primary", 800, 650, 1) Sleep(2000) Send("{ENTER}") Sleep(2000) MouseMove(800, 760,10) Sleep(2000) MouseClick("primary", 800, 760, 1) Sleep(2000) Send("{ENTER}") Else MouseMove(521, 650,10) ; BOTÃO DE ENTRADA Sleep(2000) MouseClick("primary", 521, 650, 1) Sleep(2000) Send("{ENTER}") Sleep(2000) MouseMove(521, 760,10) Sleep(2000) MouseClick("primary", 521, 760, 1) Sleep(2000) Send("{ENTER}") EndIf #ce Sleep(2000) WinKill("Frequência - Universidade Federal do Paraná") Sleep(2000) WinKill("C:\REGISTRO\chromedriver.exe") Exit We're back with my script that records entries and exits at my institution. Please do not record my entries or exits. This could harm me. In addition to the fact that the browser crashes when I'm not watching, it also doesn't record the values in the values.ini file. Reading the file goes smoothly. Thank you for your attention to my problem and I remain available for clarification. Thank you very much.
Danp2 Posted February 4, 2022 Posted February 4, 2022 Quote #include <Chrome.au3> _ChromeStartup("-kiosk http://www.intranet.ufpr.br/frequencia/","C:\Arquivos de Programas\Google\Chrome\Application\chrome.exe") You can't use the Chrome UDF with the Webdriver UDF. There are plenty of examples around that demostrate the proper way to launch Chrome with chromedriver. Latest Webdriver UDF Release Webdriver Wiki FAQs
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