Can't retrieve links inside Frame - autoit

I am trying to use AutoIt to retrieve some data from this website:
http://www.acgme.org/adspublic/default.asp
Unfortunately, the page uses frames and I'm having trouble navigating to the page where the data is.
The link is "Accredited Programs"
#include <IE.au3>
$URL="http://www.acgme.org/adspublic/"
$MyIExplorer=_IECreate($URL,1,1,1,1)
Local $theFrame = _IEGetObjById($MyIExplorer,"control")
MsgBox(0,"The Frame",$theFrame.src)
Local $oLinks = _IELinkGetCollection($theFrame)
MsgBox(0, "Link Count", #extended & " links found")
When I run the code above, I am able to populate $theFrame with the correct frame object that houses the "Accredited Programs" link, but that's as far as I can get. The $oLinks collection comes back empty.

Frames are rather special. Use _IEFrameGetObjByName instead.
#include <IE.au3>
$URL="http://www.acgme.org/adspublic/"
$MyIExplorer=_IECreate($URL,1,1,1,1)
Local $theFrame = _IEFrameGetObjByName($MyIExplorer,"control")
Local $oLinks = _IELinkGetCollection($theFrame)
MsgBox(0, "Link Count", #extended & " links found")

Related

Conditional include of file

I'd like to include certain script only if it's present. Unfortunately #include is processed before the execution, so I can't make it conditional like this:
If FileExists(#ScriptDir & "\common.au3") Then
#include "common.au3"
EndIf
I tried to use Execute to evaluate the read file in place via Execute(ReadFile(...)). But that seems to only process single statements - I couldn't declare multiple functions for example.
Is there a different way to conditionally include another file?
Probably not a good design choice but if you really need to do somethin like this, try #OnAutoItStartRegister:
#OnAutoItStartRegister "_OnAutoItStart_CreateIncludes"
#include "include_collection.au3"
If IsDeclared("iExample_Common") Then
MsgBox(64, "", "Common.au3 exists")
Else
MsgBox(16, "", "Common.au3 wasnt included")
EndIf
MsgBox(0, "", "Your Script here")
Func _OnAutoItStart_CreateIncludes()
If StringInStr($CmdLineRaw, '-_OnAutoItStart_CreateIncludes', 1) Then Return
If FileExists(#ScriptDir & "\common.au3") And Not StringInStr(FileRead("include_collection.au3"), '#include "common.au3"') Then
FileWrite("include_collection.au3", '#include "common.au3"')
EndIf
$iPID = Run('"' & #AutoItExe & '" ' & $CmdLineRaw & ' -_OnAutoItStart_CreateIncludes', #WorkingDir, Default, 2)
While ProcessExists($iPID)
ConsoleWrite(StdoutRead($iPID))
Sleep(10)
WEnd
Exit
EndFunc ;==>_OnAutoItStart_CreateIncludes
Create an additional empty file "include_collection.au3" as well.
In this example, I created "commons.au3" containing a statement "$iExample_commons = 1234'.
Note: Once the file is included this way, it should not be deleted otherwise your script will fail again. This could probably be overcome too but at some point it will become very messy.
Maybe it's a better Idea to wrap a launcher around your application which will add/remove include lines before startup as needed.

Check if WinList() contains a certain title

I am listing all open windows using WinList() to get window title and -handle in AutoIt.
I want to check if resulting array contains a specific title. What is the best way to do this? There is no WinList().Contains("TitleName") or something like that.
Local $aList = WinList() ;Gets a list of Window Titles and IDs
OK, I got it now:
For $i = 1 To $aList[0][0]
If $aList[$i][0] = "Title/String you search for" Then
MsgBox($MB_SYSTEMMODAL, "", "MessageBox shows this text if title is in list.")
EndIf
Next
You could also use something similar to what you wrote.
#include <Array.au3>
Opt("WinDetectHiddenText", 0) ;0=don't detect, 1=do detect
Opt("WinSearchChildren", 0) ;0=no, 1=search children also
Opt("WinTextMatchMode", 1) ;1=complete, 2=quick
Opt("WinTitleMatchMode", 1) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
Local $title = 'AutoIt Help (v3.3.14.2)'
Local $aList = WinList()
;~ _ArrayDisplay($aList)
Local $iIndex = _ArraySearch($aList,$title)
WinActivate($aList[$iIndex][1], '')
Window exists?
"I am listing all open windows … I want to check if … contains a specific title. What is the best way to do this?"
As per Documentation - Function Reference - WinExists() :
Checks to see if a specified window exists.
Example.
Global Const $g_sWndTitle = 'Window title here'
If WinExists($g_sWndTitle) Then WinFlash($g_sWndTitle)
Retrieve window handle, -text and -title
Handle
"… to get window title and -handle …"
As per Documentation - Function Reference - WinGetHandle() :
Retrieves the internal handle of a window.
Example:
Global Const $g_sWndTitle = 'Window title here'
Global $g_hWnd
If WinExists($g_sWndTitle) Then
$g_hWnd = WinGetHandle($g_sWndTitle)
WinFlash($g_hWnd)
EndIf
Text
As per Documentation - Function Reference - WinGetText() :
Retrieves the text from a window.
Example:
Global Const $g_sWndTitle = 'Window title here'
If WinExists($g_sWndTitle) Then
WinFlash($g_sWndTitle)
ConsoleWrite(WinGetText($g_sWndTitle) & #CRLF)
EndIf
Title
Likewise, WinGetTitle().

SciTE Script - How to get inside a Tree Control to set checkboxes

I'm using AutoIt and SciTE to create an installation script. The problem I am running into is that there is a tree menu for selection of features. I can select the whole treeview (SysTreeView32), but am not sure how to get inside it to check the boxes without doing a mouse move and click (not a great option).
The Treeview looks like this:
The Control Info from AutoIT is like this:
I'm sure it is possible, just can't figure out how to do it. This is my first attempt a such a script. Creating a response file does not work for this exe for some reason. So - this appears to be my only way out to create a somewhat silent install (not silent anymore, but at least automated).
* EDIT - Current State of Things *
I did figure out how to do some of this, but I still can't figure out if the items is selected before accessing it. So - since it toggles, I could be turning off a feature I want!
$hWnd = WinWaitActive($WindowTitle, 'Select Features')
$tvCtl = ControlGetHandle($WindowTitle, '', 'SysTreeView321')
$firstItem = _GUICtrlTreeView_FindItem($tvCtl, 'eBooks')
_GUICtrlTreeView_SelectItem($tvCtl, $firstItem, $TVGN_FIRSTVISIBLE)
_GUICtrlTreeView_ClickItem($tvCtl, $firstItem, "left", True, 1)
Send('{SPACE}')
I wouldn't think I would have to send the space since I sent the ClickItem, but seems so.
I could also do this:
ControlTreeView($hWnd, '', $tvCtl, 'Select', '#0')
ControlSend($hWnd, '', $tvCtl, ' ')
That will toggle the first one. So - i can count them all up and do it that way.
But when I check for "IsEnabled" or "IsChecked", it always says NO. So - I can't check the ones I need only. I have to hope their status is what I expect.
Here is how I am checking "IsChecked" and "IsEnabled":
If ControlCommand($hWnd, '', $logTool, 'IsEnabled') then
ConsoleWrite('Log Tool - IsEnabled' & #CRLF)
Else
ConsoleWrite('Log Tool - NOTEnabled' & #CRLF)
EndIf
and
If ControlCommand($hWnd, '', $logTool, 'IsChecked') then
ConsoleWrite('Log Tool - IsChecked' & #CRLF)
Else
ConsoleWrite('Log Tool - NOTChecked' & #CRLF)
EndIf
It always comes back NOTEnabled and NOTChecked. I made sure that I ran the same procedure above: FindItem, SelectItem, ClickItem. And, the correct item is highlighted/selected when this procedure is run - I can see that. So - it just isn't returning a proper value.
Opt('WinTitleMatchMode', 2)
$hWnd = WinGetHandle("InstallShield Wizard") ; Notice the correct title
$hTree = ControlGetHandle($hWnd, '', "[CLASS:SysTreeView32;INSTANCE:1]")
; == Now you can interact with the treeview with functions from "GuiTreeView.au3"
EDIT:
Try this
; Select the item so:
_GUICtrlTreeView_SelectItem($hTree, $hItem, $TVGN_CARET)
; Get checked state:
_GUICtrlTreeView_GetChecked($hTree, $hItem)
For more deatails read the AutoIt help.

autoit IE click on a button in a website

I am trying to open a link by clicking on button inside a website.
This is the element :-
<div class="btn3">Like</div>
I tried this
$oBtn.classname = _IEGetObjById($oIE, "Like")
_IEAction($oBtn, "click")
not working. any help. Please.
You are doing it all wrong.
Try reading the help file.
This will work
Local $oInputs = _IETagNameGetCollection($oIE, "div")
For $oInput In $oInputs
If $oInput.classname == "btn3" Then _IEAction($oInput, "click")
Next
You can use $oBtn.classname only if you create an internet application object or an xml object with autoit. OR if you use _IETagNameGetCollection()
Here is an example:
#include <IE.au3>
Local $oIE = _IE_Example("form")
Local $oInputs = _IETagNameGetCollection($oIE, "input")
Local $oBtn
For $oInput In $oInputs
if $oInput.class = "btn3" Then
$oInput.Click
ExitLoop
Next
_IEQuit($oIE)
Of course you will need a little modification to the code since we know nothing about the website you are trying to automate

`ControlCommand` not working with `ComboLBox`

Instead of returning the currect selected font, it returns 0.
ShellExecute("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("!O")
Send("F")
WinWaitActive("Font")
$select = ControlCommand("Font", "", "[CLASS:ComboLBox; INSTANCE:1]", "GetCurrentSelection", "")
MsgBox(0,"", $select)
That control is actually a "Combo L Box", not a ComboBox. As the AutoIt helpfile says under ControlCommand:
Certain commands that work on normal Combo and ListBoxes do not work
on "ComboLBox" controls.
The ComboLBox is actually a child control of the ComboBox, and is just the drop down part of it. If you use a more advanced window finder like Spy++, you will actually see there is a ComboBox there, with two children (an Edit and the ComboLBox). So your code will work if you change "[CLASS:ComboLBox; INSTANCE:1]" to "[CLASS:ComboBox; INSTANCE:1]".
Furthermore, you can improve your code for triggering the menu item, so that the entire operation can be done in the background.
#include <WindowsConstants.au3>
#include <WinAPI.au3>
Local $IDM_FONT = 33
Local $hWindow = WinGetHandle("Untitled - Notepad")
_WinAPI_PostMessage($hWindow, $WM_COMMAND, $IDM_FONT, 0)
Local $hFontWin = WinWait("Font")
$select = ControlCommand($hFontWin, "", "ComboBox1", "GetCurrentSelection", "")
WinClose($hFontWin)
MsgBox(0,"", $select)
Alternatively, you can interact with the ComboLBox in the same way you would a listbox:
$hLBox = ControlGetHandle($hFontWin, "", "ComboLBox1")
$itemIndex = _GUICtrlListBox_GetCurSel()
$select = _GUICtrlListBox_GetText($hLBox, $itemIndex)
Why ControlCommand doesn't work with this particular type of list box I have no idea. I can only guess that internally they check the control class against "ComboBox" and "ListBox" and return zero if there is no match.
You can use ControlGetText() to read the name of the currently active font, if this is what you want to accomplish.
ShellExecute("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("!O")
Send("F")
WinWaitActive("Font")
$select = ControlGetText("Font", "", "Edit1")
MsgBox(0,"", $select)

Resources