jodayautoit Posted May 31, 2011 Posted May 31, 2011 Hi All! I started a new topic since this is related specifically to using Mozilla Firefox and the FF.au3 functions. I am confused as to how to read a webpage that has 3 frames that I was told by the software person who wrote it ,that they make every frame display in what is called the "main" page view. In otherwords the "main" page is a frame with multiple frames in that page. If that makes any sense to anyone. All I am trying to do is duplicate the same thing Mozilla does when you right click and select "This frame" and view the source code. I would like to be able to use the INetGetsurce function to read a webpage before and after it is updated to verify a function had completed. Basically when the "main" page is up ,a mouse click operation selects a download of a file. Once the file is downloaded the page is updated with " The file has successfully downloaded" or " File has failed". I have looked at _FFFrameEnter, Get etc. but this specific page does not have an ID. If someone could point me or provide a better example of how to read a webpage that has 3 or more frames and get the source code from each I might be able to figure it out. The FF.au3 documentation does not have an example that makes sense to me for this purpose. I am modifying my IE test script that works to work using Mozilla Firefox and I did not have to get into the Frames of the pages until now. Thanks jodayautoit.
somdcomputerguy Posted May 31, 2011 Posted May 31, 2011 Look at the source code of the index page, or the 'main' page that is called. You will see code like this:<FRAME SRC="frame1_title.html" NAME="TITLE"> <FRAME SRC="frame1_body.html" NAME="MAIN">The src tag values contain the html pages that are loaded together to form the whole thing. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
jodayautoit Posted June 1, 2011 Author Posted June 1, 2011 Hi Bruce! I viewed the source code of the main page and it calls this page with the code below. <td class="ABCD" align="left" nowrap><p align="left"><font face="Helvetica" size="1" color="#0000FF"><img src="sbullet.gif" alt="sbullet.jpg (58 bytes)" WIDTH="5" HEIGHT="11"></font><a href="htm_config.htm?SESSION_ID=???????" target="main" >Configuration File</a></td> </tr> This is the code I used that you previously suggested for my IE test script and it works but it does not read the source page once it has been updated with new information. It appears to just call that webpage as if it was to load for the first time. I thought by putting a "wait" for the page or "sleep" it would call/read the page with the update. The only difference between the first call of the page and when the imported files is uploaded is " Import file successfully" gets updated on the page. I am trying to read the page when that statement is printed to the page. I am confused how to get my script to read the page at that time. My script reads the page fine but not when the update happens. If that makes any sense. Any suggestions are greatly appreciated. I have looked in the help and on-line. I have not found any good examples to show a way to do this if it is possible. Local $URL_Array[2] = ["http://" & $sourceip & "", "http://" & $sourceip & "/htm_config.htm/htm_login.htm "] Local $Text_Array[2] = ["Web", "Import File"] For $a = 0 To 1 ConsoleWrite("Checking.. " & $URL_Array[$a] & " - ") FileWrite($file, "Checking.. " & $URL_Array[$a] & " - ") If StringInStr(_INetGetSource($URL_Array[$a]), $Text_Array[$a], 2) <> 0 Then ConsoleWrite("Page OK" & @LF) FileWrite($file, "Page OK" & @LF) ConsoleWrite("***** _INetGetSource *****" & @CR & _INetGetSource("http://" & $sourceip "/htm_config.htm/htm_login.htm ") & @CR & @CR) Thanks jodayautoit
somdcomputerguy Posted June 1, 2011 Posted June 1, 2011 Put the whole For loop in a While loop. 'While 1' is fine. The last statement in the While loop should be Sleep(however long you want the wait to be). This will repeat the 'check' process (what's in the For loop) after every Sleep. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
somdcomputerguy Posted June 1, 2011 Posted June 1, 2011 Here is a highly modified (and hopefully easier to understand) version of code that I use. Basically, this code checks a page for several different 'changes' every 30 seconds. While 1 For $a = 0 To 4 If StringInStr(_INetGetSource($URL), $Text_Array[$a], 2) <> 0 Then Actions() ;If text does exist Sleep(100) Next Sleep(30 * 1000) WEnd - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
jodayautoit Posted June 1, 2011 Author Posted June 1, 2011 Hi Bruce! I added the While loop modified to my code and that did read the page 4 times but it read it the same each time as if it loaded it new each time. It did not just do a read of what was there once the page got refreshed so it did not read the "Import file successfully line" that gets updated on the page. I can view it manually as I mentioned using the right mouse click on the page and select this frame, view source code. I suppose I could record the right mouse click and select this frame/view source code and then have it read the page to see if that works. I think it has to do with the piece of equipment is running the webpage application and I am not sending the correct request or something. Any ideas that I could try? thanks jodayautoit
somdcomputerguy Posted June 1, 2011 Posted June 1, 2011 (edited) It sounds as though it's reading a cached version of that page (on subsequent reads). I am not sure how to workaround this. I know how to do a hard refresh in a browser, but not with the _InetGetSource function. The INetGet and INetRead functions have an option to 'force a re-load', so one of those will probably work in this case. Their operation is similar to _INetGetSource, check the help file for details though. Edited June 1, 2011 by somdcomputerguy - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
jodayautoit Posted June 1, 2011 Author Posted June 1, 2011 Hi Bruce! I got it finally by trial/error and some more research on the functions. In my case you have to figure out the frame number then enter it to perform the read function of the HTML code without reloading the page. I still do not understand why the INetGetsource did not work even when I put a wait or sleep for 60000. In any case I have a solution for the moment. Once I get this script working I will post it so others can use it as an an example. Thanks for the help jodayautoit If @error = 0 Then ; filtered source-code _FFFrameEnter(3) $sHTML = _FFReadHTML("html", 8) _FFFrameLeave() If Not @error Then ;Msgbox(64, "Sourcecode", StringLeft($sHTML, 1000)) ConsoleWrite("Page sourcecode has been read" & @LF) Else ConsoleWrite("Page sourcecode has not been read" & @LF) EndIf Sleep(60000) If @error = 0 Then ; filtered source-code _FFFrameEnter(3) $sHTML = _FFReadHTML("html", 8) _FFFrameLeave() If Not @error Then ;Msgbox(64, "Sourcecode", StringLeft($sHTML, 1000)) ConsoleWrite("Page sourcecode has been read" & @LF) Else ConsoleWrite("Page sourcecode has not been read" & @LF) EndIf EndIf EndIf
jodayautoit Posted June 2, 2011 Author Posted June 2, 2011 Hi Bruce! Small other question with frames with username passwords. I have the following code that was an example from the forum to check username and passwords.The below code is modified to what I hope todo is be able to verify any 20 character username or password. The only fault I have is this does not work if a number is substituted for either $username or $password. his is most likely a simple thing but I can not see it. Did I use the wrong function to verify the string? Basically is $username was say "1est" is will go to the username auth wrong console output. I am just trying to add some username passowrd checking to my test script. The exception is either can be any 20 characters includes numbers or dashes. Does that make sense? I won't always know what the username or password could be in my testing. They could be set to whatever. Any suggestions is greatly appreciated. I got the FFFrame function working nicely in several parts of my test script. that was the key. I can check any webpage frame on this equipment now. Thanks for the help jodayautoit $username = "Test" $password = "test" $user_pass = stringmid ($username,1,20) $user_pass2 =stringmid ($password ,1,20) consolewrite ("- $userpass = "&$user_pass&@lf) consolewrite ("- $userpass = "&$user_pass2&@lf) ;then check if user and pass is ok $auth = stringinstr ($user_pass,"") if $auth = 0 Then if $auth = $username Then consolewrite ("+ auth ok"&@lf) Else consolewrite ("! User auth wrong, do nothing"&@lf) EndIf EndIf $auth1 =stringinstr ($user_pass2,"") if $auth1 = 0 Then if $auth1 = $password Then consolewrite ("+ auth ok"&@lf) Else consolewrite ("! password auth wrong, do nothing"&@lf) EndIf EndIf
jodayautoit Posted June 2, 2011 Author Posted June 2, 2011 Hi Bruce! Sorry several typos in my previous post but I think you will know what I meant. jodayautoit.
somdcomputerguy Posted June 2, 2011 Posted June 2, 2011 I have re-written your code, w/o the StringMid and StringinStr functions, as I don't think they were necessary. This code does the same thing I think you were trying to do, it just checks if the user and pass variables contain 'anything'. $username = "1Test" ;$username = "1Test1Test1Test1Test1Test" ; 25 chars $password = "1test" If $username <> '' Then consolewrite ("+ auth ok"&@lf) Else consolewrite ("! User auth wrong, do nothing"&@lf) EndIf If $password <> '' Then consolewrite ("+ auth ok"&@lf) Else consolewrite ("! password auth wrong, do nothing"&@lf) EndIf Use the StringLen function if the user or pass string has to be at least 20 chars. (or if it's too long or too short, whatever your requirements are). So, to check if $username contains at least 1, but not more than 20 characters, the first If statement could look like this: If $username <> '' And StringLen($username) < 21 Then - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
jodayautoit Posted June 2, 2011 Author Posted June 2, 2011 Hi Bruce! Thanks. The code you rewrote is what I was looking for. I do want to add the 1-21 characters so I will add that line as well. If I understand you correctly the StringinStr and other String functions that I used are more specific to what type characters to check and to pick a location. Where as I just wanted to find out if the user entered something in there and do not care what it is as long as it is at least 1-21 characters. I think I got it. I probably should look at more simple examples for the varaiables and the operands of them. I did not understand that if $somevariable <> ' ' then do something or do nothing was equal to if $somevariable contains anything then do something code or do nothing code. the key was the "< >" and the ' ' . I am learning still but I am getting there. once this script is done it will be cool. So far it works great. Firefox application loads the username/password (now with the checking) is working and I can read the HTML from any of the webpages or the Frames. All in all I should be able to test this equipment for the basic functions and be done with it. I can later as I learn more about autoit functions get more advanced. I appreciate all the help you have provided and examples. Thanks again jodayautoit.
somdcomputerguy Posted June 3, 2011 Posted June 3, 2011 If $somevariable <> ' ' ThenTechnically, that line reads like this: If $somevariable doesn't equal (<>) a null string ('' (two single quotes, or it could be two double quotes I guess, "")) Then.. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
jodayautoit Posted June 8, 2011 Author Posted June 8, 2011 Hi all! This is my test script edited as an example to get a Mozilla Firefox browser from a valid IP address/username/password. This is just an example of how I got my test script to work and test my particular project. If someone runs this it will only open a browser to a device that has webpages at a specific IP address/username/password then close the browser after it reads whatever html is shown. I appreciated everyones input on how to do some of the functions. I just wanted to post the results. thanks again to all that provided input jodayautoit expandcollapse popup; ; AutoIt Version: 3.0 ; Language: English ; Platform: Win9x/NT ; Author: jodayautoit and assitance from Autoit forum(Bruce and others) ; ; Script Function: ; Opens an Internet Explorer Browser Web with a given test username and password ; ; Note this script has been edited so it will not do anything but bring up Firefox. This is just for example of how to check webpages and ones with frames ;for valid information. #include <FF.au3> #include <INET.au3> ; Prompt the user to run the script - use a Yes/No prompt (4 - see help file) $answer = MsgBox(4, "Web Script", "This script will open Mozilla FireFox browser and Open a Web Session. Run?") ; Check the user's answer to the prompt (see the help file for MsgBox return values) ; If "No" was clicked (7) then exit the script If $answer = 7 Then MsgBox(0, "Web", "OK. Bye!") Exit EndIf ;Code to get user input for IP address $sourceip = InputBox("Web Test Script", "Enter the IP address of the Web to be tested. Example X.X.X.X") ;Code to get user input for Username $sourceuser = InputBox("Web Test Script", "Enter the Username of the Web to be tested. Needs to be 4-21 characters .Example Web") ;Code to get user input for Password $sourcepassword = InputBox("Web Test Script", "Enter the Password of the Web to be tested. Needs to be 4-21 characters ", "", "*") ;Code to check that IPaddress, Username and Password have been entered. Not a validation of correct input just something is entered. ;IPaddress is limited to 17 characters ;Username and Password limited to 21 characters If $sourceip <> '' And StringLen($sourceip) < 17 Then ConsoleWrite("- $sourceip = " & $sourceip & @LF) ConsoleWrite("+ auth ok" & @LF) Else ConsoleWrite("! User auth wrong, do nothing" & @LF) MsgBox(0, "IPaddress Fail ", "IPaddrress is not 12 characters") Exit EndIf If $sourceuser <> '' And StringLen($sourceuser) < 21 Then ConsoleWrite("- $Username = " & $sourceuser & @LF) ConsoleWrite("+ auth ok" & @LF) Else ConsoleWrite("! User auth wrong, do nothing" & @LF) MsgBox(0, "Username ", "Username is not between 1-21 characters") Exit EndIf If $sourcepassword <> '' And StringLen($sourcepassword) < 21 Then ConsoleWrite("- $Password = " & $sourcepassword & @LF) ConsoleWrite("+ auth ok" & @LF) Else ConsoleWrite("! password auth wrong, do nothing" & @LF) MsgBox(0, "Password ", "Password is not between 1-21 characters") Exit EndIf ;Code to start a Mozilla Firefox Broswer session to IPaddress entered with Username and Password Run("C:\Program Files\Mozilla Firefox\firefox.exe", "", @SW_MAXIMIZE) _WinWaitActivate("Mozilla Firefox Start Page - Mozilla Firefox", "") If _FFConnect(Default, Default, 3000) Then ; open a page at user IP Address ,Username, Password _FFOpenURL($sourceip) Sleep(2000) Send($sourceuser) Sleep(2000) Send("{TAB}") Sleep(2000) Send($sourcepassword) Send("{ENTER}") Sleep(2000) ; Code to open a file call "testresults.txt and log the same as the console output $file = FileOpen("C:\testresults.txt", 1) ; Check if file opened for writing OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf FileWrite($file, "Test Results For Web" & @CRLF) FileWrite($file, "Begin testing" & @LF) ;Code to verify IP address is active Ping($sourceip, 500) If @error = 0 Then ConsoleWrite("Pass Ping" & @LF) FileWrite($file, "Pass Ping" & @LF) EndIf ; Mouseclick (x,y) Some location ; Then check Frame for whatever information needed to verify a files was loaded If @error = 0 Then ; filtered source-code _FFFrameEnter(3) $sHTML = _FFReadHTML("html", 8) _FFFrameLeave() If Not @error Then ;Msgbox(64, "Sourcecode", StringLeft($sHTML, 1000)) ConsoleWrite("Page sourcecode has been read" & @LF) Else ConsoleWrite("Page sourcecode has not been read" & @LF) EndIf Sleep(30000) If @error = 0 Then ; filtered source-code _FFFrameEnter(3) $sHTML = _FFReadHTML("html", 8) $testtext = "( Import Was Successful.)" If StringInStr($sHTML, $testtext) Then ConsoleWrite(" Import was Successful" & @LF) FileWrite($file, " Import was Successful" & @LF) Else ConsoleWrite(" failed stop testing" & @LF);put the exit of script due to failure _FFFrameLeave() EndIf EndIf If Not @error Then ;Msgbox(64, "Sourcecode", StringLeft($sHTML, 1000)) ConsoleWrite("Page sourcecode has been read" & @LF) FileWrite($file, "Page sourcecode has been read" & @LF) Else ConsoleWrite("Page sourcecode has not been read" & @LF) FileWrite($file, "Page sourcecode has not been read" & @LF) EndIf EndIf _WinWaitActivate("Login Page - Mozilla Firefox", "") Local $URL_Array[2] = ["http://" & $sourceip & "", "http://" & $sourceip & "/htm_filepage "] Local $Text_Array[2] = ["Web", " Filepage"] For $a = 0 To 1 ConsoleWrite("Checking.. " & $URL_Array[$a] & " - ") FileWrite($file, "Checking.. " & $URL_Array[$a] & " - ") If StringInStr(_INetGetSource($URL_Array[$a]), $Text_Array[$a], 2) <> 0 Then ConsoleWrite("Page OK" & @LF) FileWrite($file, "Page OK" & @LF) Else ConsoleWrite("Page Not OK" & @LF) FileWrite($file, "Page Not OK" & @LF) EndIf Next ;Code to check if correct page is loaded. If @error = 0 Then ; filtered source-code $sHTML = _FFReadHTML("html", 7) If Not @error Then ;Msgbox(64, "Sourcecode", StringLeft($sHTML, 1000)) ConsoleWrite("Page sourcecode has been read" & @LF) Else ConsoleWrite("Page sourcecode has not been read" & @LF) EndIf EndIf Local $Text = "Login"; change this to something on the page If StringInStr($sHTML, $Text, 2) <> 0 Then ; MsgBox(64, "Source code", "Passed:") ConsoleWrite("Login Page loaded correctly" & @LF) Else ; MsgBox(64, "Source code", "Failed :" & @LF) ConsoleWrite("Login Page not loaded correctly" & @LF) EndIf ConsoleWrite("Checking.. Page loaded " & @LF) FileWrite($file, "Checking .. Page loaded " & @LF) ;add same code as the IE script to see if it can be adapted for this script Local $URL_Array[2] = ["http://" & $sourceip & "", "http://" & $sourceip & "/htm_page1"] Local $Text_Array[2] = ["Web", "Page1"] For $a = 0 To 1 ConsoleWrite("Checking.. " & $URL_Array[$a] & " - ") FileWrite($file, "Checking.. " & $URL_Array[$a] & " - ") If StringInStr(_INetGetSource($URL_Array[$a]), $Text_Array[$a], 2) <> 0 Then ConsoleWrite("Page OK" & @LF) FileWrite($file, "Page OK" & @LF) Else ConsoleWrite("Page Not OK" & @LF) FileWrite($file, "Page Not OK" & @LF) EndIf Next #Region --- Au3Recorder generated code Start --- ;Code to verify IP address is active Ping($sourceip, 500) If @error = 0 Then ConsoleWrite("Pass Ping" & @LF) FileWrite($file, "Pass Ping" & @LF) EndIf ;MsgBox(0, "", "Page found!") ;Code to check if correct page is loaded. #Region --- Au3Recorder generated code Start --- _WinWaitActivate("Login Page - Mozilla Firefox", "") ;MouseClick(x,y)next location and check Sleep(2000) Local $Text = "Login"; change this to something on the page If StringInStr($sHTML, $Text, 2) <> 0 Then ; MsgBox(64, "Source code", "Passed:") ConsoleWrite("Login Page loaded correctly" & @LF) Else ; MsgBox(64, "Source code", "Failed :" & @LF) ConsoleWrite("Login Page not loaded correctly" & @LF) EndIf ConsoleWrite("Checking.. Page loaded " & @LF) FileWrite($file, "Checking .. Page loaded " & @LF) ;add same code as the IE script to see if it can be adapted for this script Local $URL_Array[2] = ["http://" & $sourceip & "", "http://" & $sourceip & "/htm_page2 "] Local $Text_Array[2] = ["Web", "Page2 "] For $a = 0 To 1 ConsoleWrite("Checking.. " & $URL_Array[$a] & " - ") FileWrite($file, "Checking.. " & $URL_Array[$a] & " - ") If StringInStr(_INetGetSource($URL_Array[$a]), $Text_Array[$a], 2) <> 0 Then ConsoleWrite("Page OK" & @LF) FileWrite($file, "Page OK" & @LF) Else ConsoleWrite("Page Not OK" & @LF) FileWrite($file, "Page Not OK" & @LF) EndIf Next ; Put more Code for more web pages and mouse clicks. ;Close Browser This mouse click is for a maximized screen and will click the X button to close the FireFox browser MouseClick("left", 1659, 16, 1, 80) Sleep(2000) ; Prompt the user to End the script - use a Yes/No prompt (4 - see help file) $answer = MsgBox(4, "AutoIt Example (English Only)", "This Test script has completed the Web Session and closed Internet Browser, Stop Script?") ; Check the user's answer to the prompt (see the help file for MsgBox return values) ; If "No" was clicked (7) then exit the script If $answer = 7 Then MsgBox(0, "AutoIt", "OK. Bye!") Exit Else ;Run ("Notepad.exe\testresults.txt") Run("C:\Program Files\Windows NT\Accessories\wordpad.exe " & "c:\testresults.txt") EndIf Exit EndIf #Region --- Internal functions Au3Recorder Start --- Func _WinWaitActivate($title, $Text, $timeout = 0) WinWait($title, $Text, $timeout) If Not WinActive($title, $Text) Then WinActivate($title, $Text) WinWaitActive($title, $Text, $timeout) EndFunc ;==>_WinWaitActivate #EndRegion --- Internal functions Au3Recorder Start --- #EndRegion --- Au3Recorder generated code Start --- #EndRegion --- Au3Recorder generated code Start --- ;Exit ; Finished! This is the console output Page sourcecode has been read Login Page loaded correctly Checking.. Page loaded Checking.. http://X.X.X.X - Page OK Checking.. http://X.X.X.X/htm_page1 - Page Not OK Pass Ping Login Page loaded correctly Checking.. Page loaded Checking.. http://X.X.X.X - Page OK Checking.. http://X.X.X.X/htm_page2 - Page Not OK +>09:16:05 AutoIT3.exe ended.rc:0 >Exit code: 0 Time: 66.362 This is the testresults file output Test Results For Web Begin testing Pass Ping Page sourcecode has been read Checking.. http://X.X.X.X - Page OK Checking.. http://X.X.X.X/htm_filepage - Page Not OK Checking .. Page loaded Checking.. http://X.X.X.X - Page OK Checking.. http://X.X.X.X/htm_page1 - Page Not OK Pass Ping Checking .. Page loaded Checking.. http://X.X.X.X - Page OK Checking.. http://X.X.X.X/htm_page2 - Page Not OK [\code]
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