Jump to content

how to select a checkbox when page has no "form"


Recommended Posts

In my searching of the helpfile and forum for info on selecting checkboxes, the only method I can find uses _IEFormElementCheckBoxSelect. This requires the page to have a form. When I use $oForm = _IEFormGetCollection($oIE) I get a blank return (and @error=0). does this mean my form has a blank name? how do I reference that in my script?

Thanks All

Link to comment
Share on other sites

If form have no name, you must search by an other way...

have you an url to submit ?

Thanks for your reply wakillon. It was 3am local time when I posted and needed some zzz's. Here is the requested info. Unfortunately I have to post the HTML file as an attachment because the site is not accessable outside of our network. Script will look for the html file at c:\.

#include <IE.au3>

Dim $string="MSB 131", $Result, $site="file:///C:/pre-configured%20participants.htm"
Dim $StrLen, $cutpoint, $HTMLclip, $CheckBoxID, $PageHTML

$oIE = _IECreate ($site)
_IELoadWait ($oIE)

_SearchText ($string)  ; searches HTML for string.  
$StrLen = StringLen ($string)   ; Gets length of search string
$cutpoint = (StringInStr ($PageHTML,$string) + $StrLen)  ; gets position of end of search string in HTML
$HTMLclip = StringMid ($PageHTML,($cutpoint-150),150) ; Trims HTML at right of search string, and grabs 150 chars prior
$CheckBoxID=StringTrimLeft($HTMLclip,(StringInStr ($HTMLclip, "h323",0,-1)))  ; gets first instance of "h323" from right to left and trims left
$CheckBoxID=StringTrimRight($CheckBoxID,((StringLen ($CheckBoxID)-7))) ; grabs first 7 chars and trims rest - Looking for "h323_xx(x)" - last x must be char
$CheckBoxID=StringStripWS($CheckBoxID, 2)  ; Removes trailing space if it exists
If StringRight($CheckBoxID,1) = ">" Then $CheckBoxID = StringTrimRight($CheckBoxID,1) ; removes trailing ">" if it exists
$oForm = _IEFormGetCollection($oIE)    ; get form list
MsgBox (0,"CheckBoxID", $CheckBoxID)
MsgBox (0,"Form query", $oForm)
MsgBox (0,"Form query - @error", @error)
$oQuery = _IEFormElementGetObjByName ($oForm, $CheckBoxID) ; look for CheckBoxID 
MsgBox (0,"Form Element query", $oQuery)
MsgBox (0,"Form Element query - @error", @error)

Func _SearchText ($_TextString)
    dim $TextString = $_TextString
    $PageHTML = _IEDocReadHTML($oIE)
    $Result = StringInStr ($PageHTML, $TextString)
EndFunc

Thanks.

Link to comment
Share on other sites

Try something like this

i replace _IEFormElementCheckboxSelect by _IEAction :

#include <Ie.au3>

$sURL = "file:///" & @DesktopDir & "\pre-configured participants.htm"
$oIE= _IECreate ( $sURL )
$colForms = _IEFormGetCollection ($oIE )
For $oForm In $colForms
    $colElements = _IETagNameAllGetCollection ( $oForm )
    For $oElement In $colElements
        ConsoleWrite ( ">->-- Tag = " & $oElement.tagname & "; .id = " & $oElement.id & "; .name = " & $oElement.getAttribute ( "name", 2 ) & @CRLF )
        If StringInStr ( $oElement.getAttribute ( "name", 2 ), 'h323_' ) <> 0 Then
            _IEAction ( $oElement, "click" )
            ConsoleWrite ( '-->-- $oElement.getAttribute ( "name", 2 ) : ' & $oElement.getAttribute ( "name", 2 ) & @Crlf )
    EndIf
    Next
Next

Orange line in console give you the exact name of checkbox. Posted Image

Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

In my searching of the helpfile and forum for info on selecting checkboxes, the only method I can find uses _IEFormElementCheckBoxSelect. This requires the page to have a form. When I use $oForm = _IEFormGetCollection($oIE) I get a blank return (and @error=0). does this mean my form has a blank name? how do I reference that in my script?

Thanks All

_IEFormGetCollection returns a special variable type called an object (a form collection object in this case), so it is not actually blank. If you want a reference to a single form, you need to use the index parameter to that function. I suggest you go back and look at the documentation and examples for it again (also, examine @extended to see how many forms were in the collection).

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Try something like this

i replace _IEFormElementCheckboxSelect by _IEAction :

#include <Ie.au3>

$sURL = "file:///" & @DesktopDir & "\pre-configured participants.htm"
$oIE= _IECreate ( $sURL )
$colForms = _IEFormGetCollection ($oIE )
For $oForm In $colForms
    $colElements = _IETagNameAllGetCollection ( $oForm )
    For $oElement In $colElements
        ConsoleWrite ( ">->-- Tag = " & $oElement.tagname & "; .id = " & $oElement.id & "; .name = " & $oElement.getAttribute ( "name", 2 ) & @CRLF )
        If StringInStr ( $oElement.getAttribute ( "name", 2 ), 'h323_' ) <> 0 Then
            _IEAction ( $oElement, "click" )
            ConsoleWrite ( '-->-- $oElement.getAttribute ( "name", 2 ) : ' & $oElement.getAttribute ( "name", 2 ) & @Crlf )
    EndIf
    Next
Next

Orange line in console give you the exact name of checkbox. Posted Image

Holy crap - That works awesome! I will take some time to digest this and structure it the way I need it. Thanks Very Much for the help. I was really stuck on this one. It amazes me how you guru guys can code so tight. I bow before your Awesomeness.
Link to comment
Share on other sites

_IEFormGetCollection returns a special variable type called an object (a form collection object in this case), so it is not actually blank. If you want a reference to a single form, you need to use the index parameter to that function. I suggest you go back and look at the documentation and examples for it again (also, examine @extended to see how many forms were in the collection).

Dale

Thanks Dale. I appreciate your nudge in the right direction and that you dont just spoon feed people answers. It really helps me learn and discover. I will review those functions in great detail. As frustrating as it is to learn this stuff from scratch, taking baby steps is really rewarding. Hopefully I wont need the training wheels much longer. Very very much appreciate the assistance.

Link to comment
Share on other sites

Holy crap - That works awesome! I will take some time to digest this and structure it the way I need it. Thanks Very Much for the help. I was really stuck on this one. It amazes me how you guru guys can code so tight. I bow before your Awesomeness.

Thanks !

Glad to help you ! Posted Image

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...