RobGuy
Members-
Posts
13 -
Joined
-
Last visited
RobGuy's Achievements
Seeker (1/7)
0
Reputation
-
Windows navigation using command line arguments
RobGuy replied to mjoshi's topic in AutoIt General Help and Support
Unfortunately your Send("$DataFile") will send the literal string of characters "$DataFile" when it seems from your sample here that you would like it to say Send($DataFile) but it looks like you want to navigate the windows' explroer.exe to the path which could be accomplished rather more directly with either of these: Opt("MustDeclareVars", 1) Global $DataFile = 'C:\' Run('explorer "' & $DataFile & '"') ShellExecute($DataFile) explorer.exe supports a handful of other commandline arguments besides just the path: Opt("MustDeclareVars", 1) ;geneate a temporary file FileWrite("c:\this_temporary_file_here.txt", "test") ;could create/append to the file with an old commandline for kicks if you wanted Run('cmd /c echo temp>>c:\this_temporary_file_here.txt') ;open the explorer with that file selected by default Run('explorer /select,c:\this_temporary_file_here.txt') -
It could be helpful to do it other ways but if you really want to finish up a loop and respond to the occasion of @error someplace in the middle you can do something like this: #include <Constants.au3> Opt('MustDeclareVars', 1) Local $error, $sOut='',$p=Run( _ 'CMD /c Dir C:\&&Dir "%WINDIR%"&&Dir /s "%USERPROFILE%\My Documents"' _ , @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) ConsoleWrite('Running') While Not $error $sOut &= StdoutRead($p) $error = @error Sleep(500) ConsoleWrite('.') WEnd ConsoleWrite($sOut)
-
If you have a look at the code of the page and find the object that says the "onclick='.....'" which triggers the hide/unhide in question then get hold of a reference to that object using something like getElementById or getElementsByTagName(though this one would require iteration over the collection to find the specific element you want) then fire the ol' onclick programmatically .. a super simplified example of what I mean: Opt("MustDeclareVars", 1) Local $oIE = ObjCreate("InternetExplorer.Application") $oIE.Visible = True $oIE.Navigate("About:Blank") While $oIE.ReadyState <> 4 Sleep(250) WEnd Local $oDiv = $oIE.document.createElement('div'); $oDiv.ID = "oDiv" $oDiv.InnerHTML = "<div onclick=""alert('Clicked!');"" id=""oDiv1"">Hey there</div>" _ & "<div onclick=""document.getElementById('oDiv1').click()"">Why hello</div>" _ & "<div onclick=""document.getElementById('oDiv1').fireEvent('onclick')"">ahoy!</div>" $oIE.Document.Body.appendChild($oDiv) $oDiv = $oIE.document.getElementById("oDiv1") $oDiv.Click() $oDiv.fireEvent('onclick')
-
Extract data from Silverlight
RobGuy replied to Yogi Yang's topic in AutoIt General Help and Support
Since web based automation requires interaction with the document object of the page being interfaced with and the Au3Info tool only displays those itmes in or around the rendered page that are directly visible to the rest of the operating system outside of the browser it may be simpler to take a little more round-about approach. I have not worked with SilverLight but my brief searches seem to indicate that it exposes methods and properties through the document object model of the browser so you may be able to automate your SilverLight object by getting hold of the InternetExplorer.Application object that refers to the page your SilverLight control is on then using the document object model with either GetElementById (or GetElementsByTagName then iterating over the returned collection to find the one you're after) then using the methods that the object exposes to the browser to interact with it and its data. -
(Solved)Need help for link click
RobGuy replied to EmptySpace's topic in AutoIt General Help and Support
There may be a better approach to your overall problem but at the thought of just attempting a click on a series of links and carrying on only when the link is 'not found' (@ERROR = 7) you can put in a simple function '_IELinkClickByText($oIE, $s)' then 'Return @ERROR = 7' but with so many other things that could go wrong and cause the click to fail it might be helpful to just test for click success or not of _IELinkClickByText with its return of -1 on click success like: While 1 If _IELinkClickByText($oIE, "text 1") = -1 Then ;If this one succeeded then this will skip the rest in the sequence ElseIf _IELinkClickByText($oIE, "text 2") = -1 Then ;If this one succeeded then this will skip the rest in the sequence ElseIf _IELinkClickByText($oIE, "text 3") = -1 Then ;If this one succeeded then this will skip the rest in the sequence ElseIf _IELinkClickByText($oIE, "text 4") = -1 Then ;If this one succeeded then this will skip the rest in the sequence Else ;What to do if no clicks succeed EndIf ;And so on.... Wend -
Slow Reaction.. or Loop +1 [Solved]
RobGuy replied to Schoening's topic in AutoIt General Help and Support
I'm sorry, I did not expand on the assumption of what I meant '...you know that "For $i = 1 To 5"...' If you Know that the $i you are testing is the same $i in the same scope then you can use that variable in that way. If I am not able to keep track of whether a variable I am testing at the moment is the correct name for the variable I mean to reference in that scope or not then it might be best to carefuly to name every variable I use, in any project (in case a project is modified to support the possiblity of being utilized in part by other projects), a completely unique name every time, just to be sure. Perhaps something like "$the_integer_for_counting_the_number_of_times_I_looped_in_function_A_of_script_scriptadoodle", but now I'm just being silly because honestly, I meant in that statement a case where the individual is aware of what scope the variable being referenced is in and the "$i" was used as an example name only because I didn't have any more specific case in mind like "$iRowCount" or "$iLikeCountingLoops". -
How do I capture HTML without loading page?
RobGuy replied to mootius's topic in AutoIt General Help and Support
Thanks AdmiralAlkex, I've never had to spoof the User Agent in scripting (used Firefox addons many a time for it certainly, but not had to in scripting yet). mootius, Another consideration that crossed my mind is related to "wait for page loads for hundreds of listings": Are you certain that none of the data is loaded to the results page using Ajax? I had to put together an automation years ago to scrape a site for data where a portion of the page's information was brought in by kicking off an Ajax request when the page was opened so I couldn't download it directly without running it through an object that would perform the Ajax call then wait to collect the document's source until the page was fully loaded (I was specifically asked to implement the scrape in Dot Net and don't remember if I used an embedded browser object or automated an instance of Internet Explorer) -
How do I capture HTML without loading page?
RobGuy replied to mootius's topic in AutoIt General Help and Support
As far as scraping multiple pages for things related to Craigslist I've done the sort of thing in GreaseMonkey but the other way 'round (bringing a series of pages of listings together into a single larger page) but I've not explored AutoIt possibilities through Firefox for it. Like bogQ says, maybe something like _INetGetSource? Though if your intranet is using something to limit browsers to Chrome and Firefox through something like testing the User Agent then I suppose it might encounter difficulty since I believe it utilizes Internet Explorer functionality. -
Slow Reaction.. or Loop +1 [Solved]
RobGuy replied to Schoening's topic in AutoIt General Help and Support
If I may add a thought to czardas's contribution here: The fact that your variable, $i, is used to loop say from '1 to 5' then the loop exits but outside of the loop $i = 6 is occasionally potentially handy; if you have a condition which may exit the loop early and you know that "For $i = 1 To 5" then you can test "If $i < 6" outside of the loop for proof of the loop's full cycle. -
In case you follow through with Thornhunt's advice and still wonder how to proceed: you may want to iterate the collection and test each member for something that you know is unique about that form. If you know that the form is in a div with an id and that div contains only the single form then you could do something like document.getElementById("div_id").getElementsByTagName("form")[0] which would require just a few steps in an AutoIt script: capture document.getElementById("div_id") in a variable then use that object's getElementsByTagName to capture that collection in a variable then set your form's variable to the first member of that collection. There may be a way to do this utilizing IE.au3, I've just not used it myself if there is on account of most of my work with DOM being outside of AutoIt
-
capturing text on "ill behaved" screens or "controls"
RobGuy replied to joseLB's topic in AutoIt General Help and Support
Unfortunately what we see at the screen is not just 'text' even when it appears to be text. For instance, in VB applications of yore you might come across the old MSFlexGrid control displaying data in a spreadsheet-like layout. That data can only be programmatically interfaced with either inside of the compiled application itself or by subclassing the control with other interesting programming jiggery. Without getting a hand inside the active thread of the application with the FlexGrid your only other option is OCR. Documents displayed in browsers are also a lovely can of worms because of their existence as a rendered document object model. The text we get from control-c is the result of inner hoodoo the browsers perform and can vary from one browser to the next depending on how they choose to interpret the DOM into plain text (for instance the differences in the way Internet Explorer and Firefox will paste text from some tables). I've not worked with them before but assuming the ThunderRT6PictureBox is a VB6 PictureBox then (from MSDN) "The Visual Basic 6.0 PictureBox control is a container control; in addition to displaying pictures it can be used to group and display other controls..." so assuming also that the text visible in the box is not text rendered as an image but is a collected control which has its text stored inside itself then it may be as frustratingly difficult to interact with as the FlexGrid. -
For anyone else who might wonder on the further details of the differences between the hand-coded script and recorded script: Along with what sleepydvdr mentioned about the title bar, and possibly the most trouble-prone part of the recorder's script in this case, is the MouseClick. What coordinate a control happens to sit at when it's clicked on is what the recorder can capture but that changes every time the window is moved around and can often not be predicted with any accuracy from one launch of an application to the next. The basic and more accurate methods of direct interaction with the control (depending on the need, but likely ControlClick for a simple mouse click if that left click was clicking on a button) require information like the window title or captured current handle of a window (if identified earlier in the script) and control's identifier or captured handle in order to directly interact with them (as in your example where you have utilized ControlSend with the window title text and controlID).
-
Excel Multiple Column Sort
RobGuy replied to HighlanderSword's topic in AutoIt General Help and Support
I believe that the Excel.Application's Range object's Sort method supports only 3 keys internally: [from the Object Browser's definition] Function Sort([Key1], [Order1 As XlSortOrder = xlAscending], [Key2], [Type], [Order2 As XlSortOrder = xlAscending], [Key3], [Order3 As XlSortOrder = xlAscending], [Header As XlYesNoGuess = xlNo], [OrderCustom], [MatchCase], [Orientation As XlSortOrientation = xlSortRows], [sortMethod As XlSortMethod = xlPinYin], [DataOption1 As XlSortDataOption = xlSortNormal], [DataOption2 As XlSortDataOption = xlSortNormal], [DataOption3 As XlSortDataOption = xlSortNormal]) A four key sort can be accomplished, I believe, utilizing the Sort object. In VBA it would look like: Sub do_sort() With ActiveSheet.Sort .SortFields.Clear .SortFields.Add Range("G2:G13595"), xlSortOnValues, xlAscending .SortFields.Add Range("F2:F13595"), xlSortOnValues, xlAscending .SortFields.Add Range("E2:E13595"), xlSortOnValues, xlAscending .SortFields.Add Range("C2:C13595"), xlSortOnValues, xlDescending .SetRange Range("A1:M13595") .Header = xlYes .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With End Sub ... and in AutoIt we would have something like: Opt("MustDeclareVars", 1) Const $xlSortOnValues = 0, $xlAscending = 1, $xlDescending = 2, $xlYes = 1, $xlTopToBottom = 1, $xlPinYin = 1 Local $oExcel, $oSheet ;Get the current open excel application $oExcel = ObjGet("", "Excel.Application") ;get first sheet $oSheet = $oExcel.ActiveWorkbook.Worksheets("Sheet1") ;Make sure no existing SortFields interfere by clearing the SortFields $oSheet.Sort.SortFields.Clear ;Add our desired sort parameters $oSheet.Sort.SortFields.Add($oSheet.Range("G2:G13595"), $xlSortOnValues, $xlAscending) $oSheet.Sort.SortFields.Add($oSheet.Range("F2:F13595"), $xlSortOnValues, $xlAscending) $oSheet.Sort.SortFields.Add($oSheet.Range("E2:E13595"), $xlSortOnValues, $xlAscending) $oSheet.Sort.SortFields.Add($oSheet.Range("C2:C13595"), $xlSortOnValues, $xlDescending) ;Make sure we have the right range targeted and options set $oSheet.Sort.SetRange($oSheet.Range("A1:M13595")) $oSheet.Sort.Header = $xlYes $oSheet.Sort.MatchCase = False $oSheet.Sort.Orientation = $xlTopToBottom $oSheet.Sort.SortMethod = $xlPinYin ;Then ready to apply the sort $oSheet.Sort.Apply If you utilize the Excel.au3 then the only constants that will still need declaration are xlSortOnValues abd xlPinYin.