Sign in to follow this  
Followers 0
ame1011

_IEFormElementRadioSelect

11 posts in this topic

I'm trying to select radio buttons on a form and although I triple and quadruple checked my code, nothing seems to be working...

Below is a portion of my code:

;attach to blackboard window
$o_IE = _IEAttach("Blackboard")
if $o_IE <> 0 Then
    $o_ContentFrame = _IEFrameGetObjByName ($o_IE, "content")
    ;FramePageInfo($o_ContentFrame)
    $o_InnerContentFrame = _IEFrameGetObjByName ($o_ContentFrame, "main")
    ;ConsoleWrite($o_InnerContentFrame.document.referrer & @CR)
    $page_text = _IEBodyReadHTML($o_InnerContentFrame)
    $o_Form = _IEFormGetCollection ($o_InnerContentFrame, 0)
    _IEFormElementRadioSelect ($o_Form, "0", "mc-ans-_4608589_1", 1, "byValue")
oÝ÷ ØÚ0jÉ⦭¡ûazfÊyÊ{­"­·*^

displays the name of the element.

However, when I use the _IEFormElementRadioSelect function as seen above, I get a "--> IE.au3 Warning from function _IEFormElementRadioSelect, $_IEStatus_NoMatch" Error. =(

Anyone have any ideas?


[font="Impact"] I always thought dogs laid eggs, and I learned something today. [/font]

Share this post


Link to post
Share on other sites



See if this works for you.

#include <IE.au3>

_IEErrorHandlerRegister()

;attach to blackboard window
$oIE = _IEAttach("Blackboard")
If IsObj($oIE) Then
    $oContentFrame = _IEFrameGetObjByName($oIE, "content")
    ;FramePageInfo($o_ContentFrame)
    $oInnerContentFrame = _IEFrameGetObjByName($oContentFrame, "main")
    ;ConsoleWrite($o_InnerContentFrame.document.referrer & @CR)
    $sPageText = _IEBodyReadHTML($oInnerContentFrame)
    $oForm = _IEFormGetCollection($oInnerContentFrame, 0)
    _IEFormElementRadioSelect($oForm, "0", "mc-ans-_4608589_1_0")
EndIf

Share this post


Link to post
Share on other sites

See if this works for you.

#include <IE.au3>

_IEErrorHandlerRegister()

;attach to blackboard window
$oIE = _IEAttach("Blackboard")
If IsObj($oIE) Then
    $oContentFrame = _IEFrameGetObjByName($oIE, "content")
    ;FramePageInfo($o_ContentFrame)
    $oInnerContentFrame = _IEFrameGetObjByName($oContentFrame, "main")
    ;ConsoleWrite($o_InnerContentFrame.document.referrer & @CR)
    $sPageText = _IEBodyReadHTML($oInnerContentFrame)
    $oForm = _IEFormGetCollection($oInnerContentFrame, 0)
    _IEFormElementRadioSelect($oForm, "0", "mc-ans-_4608589_1_0")
EndIf
Negative =(

I tried that earlier along with a bunch of other stuff.

Also, dont worry about the 'Endif' guys, i have alot more code following that snippet that resides in the if loop and i simply omitted it.


[font="Impact"] I always thought dogs laid eggs, and I learned something today. [/font]

Share this post


Link to post
Share on other sites

has anyone who's played with IE.au3 know whats going on here?

Below I'm attaching the HTML file in question, along with all the little files that Internet explorer saves when you choose 'Save As...' from the file menu.

BlackBoard.zip


[font="Impact"] I always thought dogs laid eggs, and I learned something today. [/font]

Share this post


Link to post
Share on other sites

This should either give you some ideas or confuse the hell out of you.

#include <IE.au3>

_IEErrorHandlerRegister()

$aQuestions = IniReadSection(@ScriptDir & "\questions.ini", "QUESTIONS")

$oIE = _IECreate("http://localhost/blackboard.htm", 1)
$oFrame1 = _IEFrameGetObjByName($oIE, "content")
$oFrame2 = _IEFrameGetObjByName($oFrame1, "main")
$oForm = _IEFormGetCollection($oFrame2, 0)
$oLabels = _IETagNameGetCollection($oForm, "LABEL")

For $oLabel In $oLabels
    $shtmlFor = $oLabel.htmlFor
    If StringInStr($shtmlFor, "True/False") Then
        $sQuestion = $oLabel.InnerText
        ConsoleWrite("Question: " & $sQuestion & @CRLF)
        For $i = 1 To $aQuestions[0][0]
            If StringInStr($aQuestions[$i][1], $sQuestion) Then
                $aAnswer = StringSplit($aQuestions[$i][1], "|")
                $sAnswer = $aAnswer[2]
                ConsoleWrite("Answer: " & $sAnswer & @CRLF & @CRLF)
                $oTemp = $oLabel.parentElement
                $oTemp = $oTemp.parentElement
                $oTBody = $oTemp.parentElement
                $oInputs = _IETagNameGetCollection($oTBody, "INPUT")
                For $oInput In $oInputs
                    If $oInput.value = $sAnswer Then
                        If Not $oInput.checked Then
                            $oInput.checked = True
                        EndIf
                    EndIf
                Next
            EndIf
        Next
    ElseIf StringInStr($shtmlFor, "Multiple Choice") Then
        $sQuestion = $oLabel.InnerText
        ConsoleWrite("Question: " & $sQuestion & @CRLF)
        For $i = 1 To $aQuestions[0][0]
            If StringInStr($aQuestions[$i][1], $sQuestion) Then
                $aAnswer = StringSplit($aQuestions[$i][1], "|")
                $sAnswer = $aAnswer[2]
                ConsoleWrite("Answer: " & $sAnswer & @CRLF & @CRLF)
                $oTemp = $oLabel.parentElement
                $oTemp = $oTemp.parentElement
                $oTBody = $oTemp.parentElement
                $oLabels2 = _IETagNameGetCollection($oTBody, "LABEL")
                For $oLabel2 In $oLabels2
                    If $oLabel2.InnerText = $sAnswer Then
                        $oTemp = $oLabel2.parentElement
                        $oTemp = $oTemp.previousSibling
                        $oTemp = $oTemp.previousSibling
                        $oInput = $oTemp.firstChild
                        If Not $oInput.checked Then
                            $oInput.checked = True
                        EndIf
                    EndIf
                Next
            EndIf
        Next
    EndIf
Next

Save this as "questions.ini" in the script directory.

[QUESTIONS]
1=This access control permits access from subclasses, but denies access from anywhere not in the class or its subclasses.|protected
2=This access control permits access from within the class, but denies access from anywhere else.|private
3=If z is declared public in a superclass, a subclass can modify the value of x without using a setter method in the superclass.|True
4=During compile time, the ______ type is used during type checking.|dynamic
5=When "v1.print();" is executed, we use the _______ type to determine which print method is called.|static
6=A protected method in a superclass can be accessed from the subclass.|False
7=A private method in a superclass can be accessed from the subclass.|True
8='Method lookup' and 'method dispatch' are synonymous (i.e. they mean the same thing).|False
9=When the same method call may at different times invoke different methods based on the dynamic type, this is called method|polymorphism
10=If y is declared private in a superclass, a subclass can modify the value of x without using a setter method in the superclass.|True

p.s. No these are not the correct answers!

Share this post


Link to post
Share on other sites

has anyone who's played with IE.au3 know whats going on here?

Below I'm attaching the HTML file in question, along with all the little files that Internet explorer saves when you choose 'Save As...' from the file menu.

I'm sorry, I haven't had a chance to digest and test what you have left here, but I'm afraid there is a bug in the handling of the 'name' parameter for that function. Can you please try omitting it (it is really only useful when there are more than one set of radio button sets in a form) -- just use an empty string "".

Thanks,

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

Share this post


Link to post
Share on other sites

oh wow, thanks big_daddy.

Although I consider myself proficient in autoit, I've always used UDFs to interact with objects and thus I'm unsure of some of the object syntax.

IF anyone has time, would they mind telling me where I can get a list of all the (dot functions?) as seen above?

IE: .InnerText, .parentElement


[font="Impact"] I always thought dogs laid eggs, and I learned something today. [/font]

Share this post


Link to post
Share on other sites

No problem, it was fun and I actually learned something from it. As far as the "dot funtions", these are actually properties and methods. This link should help you understand them better.

If you have anymore questions feel free to ask.

Share this post


Link to post
Share on other sites

No problem, it was fun and I actually learned something from it. As far as the "dot funtions", these are actually properties and methods. This link should help you understand them better.

If you have anymore questions feel free to ask.

Thanks again!

I've bookmarked that and the w3s Dom Object Page :P

So you know, I'm getting the answers from my mySQL database and within this hour i should have everything up and running thanks to your script. Too bad I didnt find you sooner, lol. I spent most of last night manually parsing all that HTML code :nuke:


[font="Impact"] I always thought dogs laid eggs, and I learned something today. [/font]

Share this post


Link to post
Share on other sites

For learning purposes, I'm posting the finished code below:

BTW big_daddy, if u view the source of the html file, you'll notice that the multiple choice anwers are not being passed by their name value. Instead they have numerical values. Because of this, you can't really user oInput.value

#include <IE.au3>
#include <Trim.au3>
#include <Connect.au3>
#include <MySQL.au3>
$class = "Test 1005 - Test Class"
write_answers()
func write_answers()
    $QCount = -1
    $QIndex = 0
    $MaxQIndex = 0
    $ACount = 0
    Dim $aAnswers[1][1]
    Dim $aAnswerIds[1][1]
    ;attach to blackboard window
    $oIE = _IEAttach("Blackboard")
    If IsObj($oIE) Then
        $oFrame1 = _IEFrameGetObjByName($oIE, "content")
        $oFrame2 = _IEFrameGetObjByName($oFrame1, "main")
        $oForm = _IEFormGetCollection($oFrame2, 0)
        $oLabels = _IETagNameGetCollection($oForm, "LABEL")
        $sql = _MySQLConnect($sql_user,$sql_pass,$sql_db,$sql_server)
        ;populate answer array
        For $oLabel In $oLabels
            $shtmlFor = $oLabel.htmlFor
            ;only for answers, not questions
            if StringInStr($shtmlFor, "Multiple Choice") OR StringInStr($shtmlFor, "True/False") Then
                $QIndex = 0
                $QCount = $QCount + 1
            Else
                if $MaxQIndex < $QIndex Then
                    $MaxQIndex = $QIndex
                EndIf
                ;get answer and ids
                $sCorAnswer = $oLabel.innerText
                $sCorAnswer = cleanup($sCorAnswer)
                $sCorId = $oLabel.htmlFor
                ;add to array
                ;ConsoleWrite("["&$QCount&"]"&"["&$QIndex&"]"&" = "&$sCorAnswer&@CR)
                ReDim $aAnswers[$QCount+1][$MaxQIndex+1]
                ReDim $aAnswerIds[$QCount+1][$MaxQIndex+1]
                $aAnswers [$QCount][$QIndex] = $sCorAnswer
                $aAnswerIds [$QCount][$QIndex] = $sCorId
                ;increment answer count for this question
                $QIndex = $QIndex + 1
            EndIf
        Next
        ;answer questions
        For $oLabel In $oLabels
            $ansIndex = -1
            $ansId = ""
            $shtmlFor = $oLabel.htmlFor
            ;ConsoleWrite($shtmlFor & @CRLF)
            ;multiple choice question
            if StringInStr($shtmlFor, "Multiple Choice") Then
                ;get raw question
                $sQuestion = $oLabel.innerText
                ;clean question up
                $sQuestion = cleanup($sQuestion, "sql")
                ;get correct answer
                $sAnswer = selectAnswer($sql,$class, $sQuestion)
                For $u = 0 to UBound($aAnswers, 2) - 1
                    if $aAnswers[$ACount][$u] = $sAnswer Then
                        $ansIndex = $u
                        $ansId = $aAnswerIds[$ACount][$u]
                    EndIf
                Next
                ;fill in form with correct answer leave blank is unknown
                if $ansIndex <> -1 Then
                    $oTemp = $oLabel.parentElement
                    $oTemp = $oTemp.parentElement
                    $oTBody = $oTemp.parentElement
                    $oInputs = _IETagNameGetCollection($oTBody, "INPUT")
                    For $oInput In $oInputs
                        If $oInput.id = $ansId Then
                            If Not $oInput.checked Then
                                $oInput.checked = True
                            EndIf
                        EndIf
                    Next
                Else
                EndIf
                $ACount = $ACount + 1
                ;true and false questions
            elseif StringInStr($shtmlFor, "True/False") Then
                ;get raw question
                $sQuestion = $oLabel.innerText
                ;clean question up
                $sQuestion = cleanup($sQuestion, "sql")
                ;get correct answer
                $sAnswer = selectAnswer($sql,$class, $sQuestion)
                For $u = 0 to UBound($aAnswers, 2) - 1
                    if $aAnswers[$ACount][$u] = $sAnswer Then
                        $ansIndex = $u
                        $ansId = $aAnswerIds[$ACount][$u]
                    EndIf
                Next
                if $ansIndex <> -1 Then
                    $oTemp = $oLabel.parentElement
                    $oTemp = $oTemp.parentElement
                    $oTBody = $oTemp.parentElement
                    $oInputs = _IETagNameGetCollection($oTBody, "INPUT")
                    For $oInput In $oInputs
                        If $oInput.id = $ansId Then
                            If Not $oInput.checked Then
                                $oInput.checked = True
                            EndIf
                        EndIf
                    Next
                EndIf
                $ACount = $ACount + 1
            EndIf
        Next
        _MySQLEnd($sql)
    Else
        MsgBox(0,"error", "error attaching to blackboard")
    EndIf
EndFunc   ;==>write_answers
Func selectAnswer($sql, $class, $q)
    $str = "SELECT * FROM `"&$class&" - Questions` WHERE question LIKE '%" & $q & "%'"
    $oQuery = _Query ($sql, $str)
    $count = _CountRecords2($sql, $str)
    if $count = 0 Then
        return -1
    Else
        return $oQuery.Fields("answer").value
    EndIf
EndFunc   ;==>selectAnswer
func cleanup($str, $mode = "norm")
    ;remove multiple underscores
    While StringInStr($str, "__")
        $str = StringReplace($str, "__", "_")
    WEnd
    ;trim whitespace
    $str = _ALLTRIM($str, "%%whs%%")
    if $mode = "sql" Then
        ;escape illegal character '
        $str = StringReplace($str, "'", "\'")
    EndIf
    Return $str
EndFunc   ;==>cleanup

[font="Impact"] I always thought dogs laid eggs, and I learned something today. [/font]

Share this post


Link to post
Share on other sites

For learning purposes, I'm posting the finished code below:

BTW big_daddy, if u view the source of the html file, you'll notice that the multiple choice anwers are not being passed by their name value. Instead they have numerical values. Because of this, you can't really user oInput.value

I know this, thats why I split the True/Fale and Multiple Choice into two different if statements. :P

Share this post


Link to post
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
Sign in to follow this  
Followers 0