ThomasBennett Posted September 13, 2016 Share Posted September 13, 2016 Good afternoon Everyone, I am trying to update the shutdown time on about 200 Hitachi Projectors. Each of these projectors can be accessed via an ip address. I have everything working accept for clicking OK on a JavaScript popup message. This message appears after clicking the Reset button. expandcollapse popup#include <File.au3> #include <IE.au3> ; Variable to control the sleep time throughout the script Local $oSleep_Time = 5000 ; Open the file below Local $file = FileOpen("projectors_hs.csv", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error: projectors_hs.csv not found", "projectors_hs.csv must be with this application.", 10) Exit EndIf ; Read in lines of text until the EOF is reached While 1 ; Read the .csv file Local $line = FileReadLine($file) If @error = -1 Then ExitLoop Local $line_split = StringSplit($line, ',', 1) Local $hostname= $line_split[1] Local $ip_address= $line_split[2] Local $email_1= $line_split[3] Local $email_2= $line_split[4] Local $skip= $line_split[5] Local $login= $line_split[6] ; Skip this line / record If $skip <> 'Skip' Then ; Depending upon what $login is Prompt or Web login using the correct method If $login == 'Web' Then ; Go the Network Projector homepage Local $oIE = _IECreate ("http://" & $ip_address & "/") _IELoadWait($oIE) ; Login to the Projector ; Look for html form named form01 Local $oForm = _IEFormGetObjByName($oIE, "form01") ; Look for input textbox named DATA1 Local $oUsername = _IEFormElementGetObjByName($oForm, "DATA1") ; Provide the username _IEFormElementSetValue($oUsername, "") ; Look for input textbox named DATA2 Local $oPassword = _IEFormElementGetObjByName($oForm, "DATA2") ; Provide the password _IEFormElementSetValue($oPassword, "") ; Press the Logon(submit) button _IEFormSubmit($oForm) ; Write the IP to console for review ConsoleWrite($ip_address & @LF) ; Go to the Schedule Settings / Daily page ; To Reset the Schedule using the Reset button _IENavigate($oIE,"http://" & $ip_address & "/admin/daily.html") Local $oSubmit = _IEGetObjByName($oIE, "R1") _IEAction($oSubmit, "click") ; After the click above the javascript dialog box appears ; After the click above the javascript dialog box appears ; After the click above the javascript dialog box appears Sleep (15000) ; Reset complete ; To Set a new schedule for the projector Local $oForm4 = _IEFormGetObjByName($oIE, "form01") ; Look for input textbox named D2 Local $oHour = _IEFormElementGetObjByName($oForm4, "D2") ; Provide the new hour _IEFormElementSetValue($oHour, "15") ; Find the Register button and click it Local $oBtns = _IETagNameGetCollection($oIE, "button") For $oBtn In $oBtns If String($oBtn.classname) = "btn_style7" Then _IEAction($oBtn, "click") EndIf Next _IELoadWait($oIE) ; Look for the checkbox named D1 Local $oForm5 = _IEFormGetObjByName($oIE, "form01") _IEFormElementCheckBoxSelect($oForm5, 0, "", 1, "byIndex") ; Click the Apply button Local $oBtns = _IETagNameGetCollection($oIE, "button", 0) _IEAction($oBtns, "click") _IELoadWait($oIE) ; Close Internet Explorer window ProcessClose("iexplore.exe") EndIf EndIf WEnd ; Close the file FileClose($file) Exit I am using Debug Bar in Internet Explorer and I have found the javascript code that runs when the button is clicked. Below is the HTML code of the button: <button name="R1" class="btn_style1" onclick="ResetSchedule(form01,1)" type="button">Reset</button> Below is the JavaScript code: expandcollapse popupfunction ResetSchedule(fOBJ,Flag) { switch(Flag) { case 1: str = "Are you sure you want to reset Daily Schedule?" break; case 2: str = "Are you sure you want to reset Sunday Schedule?" break; case 3: str = "Are you sure you want to reset Monday Schedule?" break; case 4: str = "Are you sure you want to reset Tuesday Schedule?" break; case 5: str = "Are you sure you want to reset Wednesday Schedule?" break; case 6: str = "Are you sure you want to reset Thursday Schedule?" break; case 7: str = "Are you sure you want to reset Friday Schedule?" break; case 8: str = "Are you sure you want to reset Saturday Schedule?" break; case 9: str = "Are you sure you want to reset Specific date No.1 Schedule?" break; case 10: str = "Are you sure you want to reset Specific date No.2 Schedule?" break; case 11: str = "Are you sure you want to reset Specific date No.3 Schedule?" break; case 12: str = "Are you sure you want to reset Specific date No.4 Schedule?" break; case 13: str = "Are you sure you want to reset Specific date No.5 Schedule?" break; default: return; } if(!confirm(str)) return; fOBJ.V1.value = 1; fOBJ.SetScheduleFlag.value = 0; if(Flag >= 9 && Flag <= 13) { fOBJ.SetScheduleMonth.value = "1"; fOBJ.SetScheduleDate.value = "1"; } tmp = parseInt(fOBJ.A1.value, 10); switch(tmp) { case 40: fOBJ.V140.value = 1; case 39: fOBJ.V139.value = 1; case 38: fOBJ.V138.value = 1; case 37: fOBJ.V137.value = 1; case 36: fOBJ.V136.value = 1; case 35: fOBJ.V135.value = 1; case 34: fOBJ.V134.value = 1; case 33: fOBJ.V133.value = 1; case 32: fOBJ.V132.value = 1; case 31: fOBJ.V131.value = 1; case 30: fOBJ.V130.value = 1; case 29: fOBJ.V129.value = 1; case 28: fOBJ.V128.value = 1; case 27: fOBJ.V127.value = 1; case 26: fOBJ.V126.value = 1; case 25: fOBJ.V125.value = 1; case 24: fOBJ.V124.value = 1; case 23: fOBJ.V123.value = 1; case 22: fOBJ.V122.value = 1; case 21: fOBJ.V121.value = 1; case 20: fOBJ.V120.value = 1; case 19: fOBJ.V119.value = 1; case 18: fOBJ.V118.value = 1; case 17: fOBJ.V117.value = 1; case 16: fOBJ.V116.value = 1; case 15: fOBJ.V115.value = 1; case 14: fOBJ.V114.value = 1; case 13: fOBJ.V113.value = 1; case 12: fOBJ.V112.value = 1; case 11: fOBJ.V111.value = 1; case 10: fOBJ.V110.value = 1; case 9: fOBJ.V19.value = 1; case 8: fOBJ.V18.value = 1; case 7: fOBJ.V17.value = 1; case 6: fOBJ.V16.value = 1; case 5: fOBJ.V15.value = 1; case 4: fOBJ.V14.value = 1; case 3: fOBJ.V13.value = 1; case 2: fOBJ.V12.value = 1; case 1: fOBJ.V11.value = 1; break; } fOBJ.R1.disabled = true; fOBJ.submit(); } When the button is clicked case 1 is ran; the dialog box appears with a title of "Message from webpage" and it has the contents "Are you sure you want to reset Daily Schedule?". I have tried using the AutoIt WindowsInfo program and the clicks, send key commands do not seem to apply to the correct window. I have put in popup message to appear when the clicks or send key commands are used and they will not appear until after I click OK or Cancel on the dialog box manually. Any suggestions or solutions are welcomed and wanted. Thank you for your time, Thomas Link to comment Share on other sites More sharing options...
Danp2 Posted September 13, 2016 Share Posted September 13, 2016 Have you reviewed this thread? ThomasBennett 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
ThomasBennett Posted September 14, 2016 Author Share Posted September 14, 2016 Good evening Danp2, Thank you for the link above; as of earlier today I had not reviewed the thread linked. As of this evening with your help and the thread the problem has been resolved. Thank you so much for the link and for your time! Here is the working code: expandcollapse popup#cs ---------------------------------------------------------------- Version: 3.5.4 Author: Script Function: To automatically update network projectors based off of a .csv file 01. Log into the projector's web interface 02. Update the projector shutdown time; end of school changed this year 03. Save the changes CSV file formatting requirements: Example: Projector Hostname,Projector IP Address,TO E-mail Address,CC E-mail Address ,Skip or Blank,Login Type Example of how the variables read the .CSV file $hostname,$ip_address,$email_1,$email_2,$skip,$login #ce ---------------------------------------------------------------- #include <File.au3> #include <IE.au3> ; Open the file below Local $file = FileOpen("projectors_hs.csv", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error: projectors_hs.csv not found", "projectors_hs.csv must be with this application.", 10) Exit EndIf ; Read in lines of text until the EOF is reached While 1 ; Read the .csv file Local $line = FileReadLine($file) If @error = -1 Then ExitLoop Local $line_split = StringSplit($line, ',', 1) Local $hostname= $line_split[1] Local $ip_address= $line_split[2] Local $email_1= $line_split[3] Local $email_2= $line_split[4] Local $skip= $line_split[5] Local $login= $line_split[6] ; Skip this line / record If $skip <> 'Skip' Then ; Depending upon what $login is Prompt or Web login using the correct method If $login == 'Web' Then ; Go the Network Projector homepage Local $oIE = _IECreate ("http://" & $ip_address & "/") _IELoadWait($oIE) ; Login to the Projector ; Look for html form named form01 Local $oForm = _IEFormGetObjByName($oIE, "form01") ;Look for input textbox named DATA1 Local $oUsername = _IEFormElementGetObjByName($oForm, "DATA1") ;Provide the username _IEFormElementSetValue($oUsername, "") ; Look for input textbox named DATA2 Local $oPassword = _IEFormElementGetObjByName($oForm, "DATA2") ; Provide the password _IEFormElementSetValue($oPassword, "") ; Press the Logon(submit) button _IEFormSubmit($oForm) Else ConsoleWrite("Login Prompt / Dialog Box login: " & $ip_address & @LF) ; Leave this for later; only 1% of the projectors use an entirely different web interface. :( ; The login portion works correctly; will have to go through each interface again different variables. :( ; Go the Network Projector homepage and Login ; Run("UAC.exe") ; Local $oIE = _IECreate ("http://" & $ip_address & "/") ; _IELoadWait($oIE) EndIf ; Main Program ; Write the IP to console for review ConsoleWrite("Starting: " & $ip_address & @LF) ; Go to the Schedule Settings / Daily page If $login == 'Web' Then _IENavigate($oIE,"http://" & $ip_address & "/admin/daily.html") Else _IENavigate($oIE,"http://" & $ip_address & "/html/daily.html") EndIf ; To Reset the Schedule using the Reset button and dismiss the JavaScript dialog box $hIE = _IEPropertyGet($oIE, "hwnd") $oButton = _IEGetObjByName($oIE, "R1") If @error = 0 And IsObj($oButton) Then _IEAction($oButton, "focus") ControlSend($hIE, "", "", "{ENTER}") WinWaitActive("[CLASS:#32770]", "") ControlClick ("[CLASS:#32770]", "OK", 1, "left", 1) Sleep (10000) ; Reset complete ; To Set a new schedule for the projector Local $oForm4 = _IEFormGetObjByName($oIE, "form01") ; Look for input textbox named D2 Local $oHour = _IEFormElementGetObjByName($oForm4, "D2") ; Provide the new hour _IEFormElementSetValue($oHour, "15") ; Find and click the Register button Local $oBtns = _IETagNameGetCollection($oIE, "button") For $oBtn In $oBtns If String($oBtn.classname) = "btn_style7" Then _IEAction($oBtn, "click") EndIf Next _IELoadWait($oIE) ; Look for the checkbox named D1 Local $oForm5 = _IEFormGetObjByName($oIE, "form01") _IEFormElementCheckBoxSelect($oForm5, 0, "", 1, "byIndex") ; Find and click the Apply button Local $oBtns = _IETagNameGetCollection($oIE, "button", 0) _IEAction($oBtns, "click") _IELoadWait($oIE) ; Give the settings time to Apply Sleep (10000) ; Close Internet Explorer window ConsoleWrite("Finished" & @LF) ProcessClose("iexplore.exe") EndIf WEnd ; Close the file FileClose($file) Exit Thank you again for your help! Please mark this post as Closed or Solved. Thank you Admin. Thomas Link to comment Share on other sites More sharing options...
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