Sign in to follow this  
Followers 0
BreCalmor

Finding a form with no name

9 posts in this topic

This is the code of the webpage I am trying to automate, which includes many forms with apparently no way to "select" them.

<table style="margin:0 auto; width:95%" cellpadding="2" cellspacing="2" border="0">
<tr class="headerCell" style="vertical-align:middle" >
    <td><strong>
        <a href="/instructor/quiz_repository.jsp?pl=qm&cl=nw_qz&srtby=q&ad=d">Quiz title</a>
        
        </strong></td>  
    <td style="width:10px;"><strong>#</strong></td>
    <td><strong>
        <a href="/instructor/quiz_repository.jsp?pl=qm&cl=nw_qz&srtby=c&ad=d">Created </a>
            
            
                <img src="/images/down_arrow.gif" alt="sorted in descending order" width="10" height="10" border="0"/> 
                
    </strong></td>
    <td><strong>
        <a href="../instructor/quiz_repository.jsp?pl=qm&cl=nw_qz&srtby=m&ad=d">Last<br/>modified</a>
            
                
    </strong></td>
    <td><strong>View</strong></td>
    <td><strong>Key</strong></td>   
    <td><strong>Edit</strong></td>
    <td><strong>Del</strong></td>
    <td><strong>Copy</strong></td>
    <td style="width:130px;"><strong>Assign to class</strong></td>  
</tr>
 
 
 
<tr>
    <td class="elementCell" style="vertical-align:middle;">
        <table cellspacing="0" cellpadding="0">
        <tr><td style="vertical-align:middle"><img src="/images/unassigned.gif" alt="unassigned quiz"/></td>
            <td style="vertical-align:middle;">Ocean Floor 5.6a - Tim</td>
        </tr>
        </table>
    </td>
    <td class="elementCell" style="width:10px;vertical-align:middle;">5</td>
    <td class="elementCell" style="font-size:80%;width:70px;vertical-align:middle;">Oct 24, 2010 2:44:23 AM</td>
    <td class="elementCell" style="font-size:80%;width:70px;vertical-align:middle;">Oct 24, 2010 2:44:38 AM</td>
    <td class="elementCell" style="width:40px;vertical-align:middle;">
        <form action="../servlet/quizrepositoryservlet" method="post">
            <input name="quiz_id" type="hidden" value="236335" />
            <input name="return_page" type="hidden" value="../instructor/quiz_repository.jsp?pl=qm&cl=qm_ov"/>
            <input name="previewbutton" type="image" src="/images/preview.gif" alt="preview appearance of quiz" width="20" height="20" border="0"/>
        </form> 
    </td>
    <td class="elementCell" style="width:40px;vertical-align:middle;">
        <form action="/servlet/quizrepositoryservlet" method="post">
            <input name="quiz_id" type="hidden" value="236335" />
            <input name="return_page" type="hidden" value="../instructor/quiz_repository.jsp?pl=qm&cl=qm_ov"/>
            <input name="anskeybutton" type="image" src="/images/answer_key.gif" alt="View the answer key for this quiz" width="20" height="20" border="0"/>
        </form> 
    </td>
    <td class="elementCell" style="vertical-align:middle;">
        <form action="/servlet/quizrepositoryservlet" method="post">
            <input name="quiz_id" type="hidden" value="236335" />
            <input name="return_page" type="hidden" value="../instructor/quiz_repository.jsp?pl=qm&cl=qm_ov"/>
            <input name="editbutton" type="image" id="editbutton" src="/images/edit.gif" alt="edit contents of quiz" width="20" height="20" border="0"/>
        </form> 
    </td>
    <td class="elementCell" style="vertical-align:middle;">
        <form action="../instructor/quiz_del_confirm.jsp?pl=qm&cl=qm_ov" method="post">
            <input name="quiz_id" type="hidden" value="236335" />
            
            <input name="deletebutton" type="image" id="deletebutton" src="/images/delete.gif" alt="delete quiz from QuizStar" width="20" height="20" border="0"/>
            
         </form>
    </td>
    <td class="elementCell" style="vertical-align:middle;">
        <form action="../instructor/quiz_duplicate.jsp?pl=qm&cl=qm_ov" method="post">
            <input name="quiz_id" type="hidden" value="236335" />
            <input name="duplicatebutton" type="image" id="deletebutton" src="/images/bwduplicate.gif" alt="duplicate this quiz" width="20" height="20" border="0"/>            
        </form>
    </td>
    <td class="elementCell" style="vertical-align:top;">
        <form action="/instructor/quiz_dates.jsp?pl=qm&cl=qm_ov" method="post">
            <input name="return_page" type="hidden" value="../instructor/quiz_repository.jsp?pl=qm&cl=qm_ov"/>
            <input name="quiz_id" type="hidden" value="236335" />
            <select name="course_id" style="min-width:100px;font-size:10px;">
            
                <option value="-1" selected>Select class</option>
            
                <option value="153272">Science</option>
            
            </select>
            
                <input name="assignbutton" type="image" id="assignbutton" src="/images/assign.gif" alt="Assign quiz to class" width="20" height="20" border="0"/>
            
        </form> 
    </td>
</tr>
 
 
 
<tr>
    <td class="elementCell" style="vertical-align:middle;">
        <table cellspacing="0" cellpadding="0">
        <tr><td style="vertical-align:middle"><img src="/images/unassigned.gif" alt="unassigned quiz"/></td>
            <td style="vertical-align:middle;">test</td>
        </tr>
        </table>
    </td>
    <td class="elementCell" style="width:10px;vertical-align:middle;">1</td>
    <td class="elementCell" style="font-size:80%;width:70px;vertical-align:middle;">Oct 23, 2010 6:33:39 PM</td>
    <td class="elementCell" style="font-size:80%;width:70px;vertical-align:middle;">Oct 23, 2010 6:34:03 PM</td>
    <td class="elementCell" style="width:40px;vertical-align:middle;">
        <form action="../servlet/quizrepositoryservlet" method="post">
            <input name="quiz_id" type="hidden" value="236298" />
            <input name="return_page" type="hidden" value="../instructor/quiz_repository.jsp?pl=qm&cl=qm_ov"/>
            <input name="previewbutton" type="image" src="/images/preview.gif" alt="preview appearance of quiz" width="20" height="20" border="0"/>
        </form> 
    </td>
    <td class="elementCell" style="width:40px;vertical-align:middle;">
        <form action="/servlet/quizrepositoryservlet" method="post">
            <input name="quiz_id" type="hidden" value="236298" />
            <input name="return_page" type="hidden" value="../instructor/quiz_repository.jsp?pl=qm&cl=qm_ov"/>
            <input name="anskeybutton" type="image" src="/images/answer_key.gif" alt="View the answer key for this quiz" width="20" height="20" border="0"/>
        </form> 
    </td>
    <td class="elementCell" style="vertical-align:middle;">
        <form action="/servlet/quizrepositoryservlet" method="post">
            <input name="quiz_id" type="hidden" value="236298" />
            <input name="return_page" type="hidden" value="../instructor/quiz_repository.jsp?pl=qm&cl=qm_ov"/>
            <input name="editbutton" type="image" id="editbutton" src="/images/edit.gif" alt="edit contents of quiz" width="20" height="20" border="0"/>
        </form> 
    </td>
    <td class="elementCell" style="vertical-align:middle;">
        <form action="../instructor/quiz_del_confirm.jsp?pl=qm&cl=qm_ov" method="post">
            <input name="quiz_id" type="hidden" value="236298" />
            
            <input name="deletebutton" type="image" id="deletebutton" src="/images/delete.gif" alt="delete quiz from QuizStar" width="20" height="20" border="0"/>
            
         </form>
    </td>
    <td class="elementCell" style="vertical-align:middle;">
        <form action="../instructor/quiz_duplicate.jsp?pl=qm&cl=qm_ov" method="post">
            <input name="quiz_id" type="hidden" value="236298" />
            <input name="duplicatebutton" type="image" id="deletebutton" src="/images/bwduplicate.gif" alt="duplicate this quiz" width="20" height="20" border="0"/>            
        </form>
    </td>
    <td class="elementCell" style="vertical-align:top;">
        <form action="/instructor/quiz_dates.jsp?pl=qm&cl=qm_ov" method="post">
            <input name="return_page" type="hidden" value="../instructor/quiz_repository.jsp?pl=qm&cl=qm_ov"/>
            <input name="quiz_id" type="hidden" value="236298" />
            <select name="course_id" style="min-width:100px;font-size:10px;">
            
                <option value="-1" selected>Select class</option>
            
                <option value="153272">Science</option>
            
            </select>
            
                <input name="assignbutton" type="image" id="assignbutton" src="/images/assign.gif" alt="Assign quiz to class" width="20" height="20" border="0"/>
            
        </form> 
    </td>
</tr>
</table>

How do I select the form with the drop down with the name of "course_id" so that I can select the specific course and then click on the assign image.

This is what I have:

; Assign the quiz
$oForm = _IETagNameGetCollection ($oIE, "FORM", 1)
; need something here to select the 6th form per table row, of the first table row
; I am not sure how to use collections nor an "indexed instance"

$oText = _IEFormElementGetObjByName ($oForm, "course_id")
; name of combo "course_id"
_IEFormElementOptionselect ($oText, "Science", 1, "byText", 1)
_IEFormImageClick ($oForm, "assign.gif", "src", 0, 1)

Any help would be greatly appreciated as I am sure I am missing the forest for the trees.

Thanks,

Bre

Share this post


Link to post
Share on other sites



_IEFormGetCollection() might be what you need. Refer to the help file for how to use it...there's a bunch of examples that should help you out.

Share this post


Link to post
Share on other sites

_IEFormGetCollection() might be what you need. Refer to the help file for how to use it...there's a bunch of examples that should help you out.

I understand, but my underlying question is how to use "a collection or indexed instance". I don't seem to find an example to pick the 6th form item, as it has neither a name or anything else that can uniquely identify the form I need.

Is the only way to figure this out is to loop through all the forms and grab the first form with the option drop down named "course_id"?

I am going to work that angle unless someone can show me an easier, more efficient way.

Thanks for all the help !!

Bre

Share this post


Link to post
Share on other sites

If you know which form instance you need, the index, specify that number in the function. Otherwise if you omit the index number it will return the entire collection, which you will loop through to each to find the one you want. Just estimate then guess and check... from what you've provided it looks like it's in the 6th form which would be index 5 so try using:

$oForm = _IEFormGetCollection($oIE, 5)

Share this post


Link to post
Share on other sites

$oForm = _IETagNameGetCollection ($oIE, "FORM", 5)

Worked this morning, but the same darn thing didn't work last night... groan.

Thanks for everyone's help. It appears I didn't need it, was just being stupid.

Have a Blessed Day !!

Bre

Share this post


Link to post
Share on other sites

This may sound like grousing, but it is a serious question.

This specific question occurs so often in this forum, can you please make a suggestion on how the documentation can be enhanced to prevent it?

The Remarks in the helpfile for the function _IEFormGetObjByName states:

Remarks

If the desired form element does not have a name or ID, _IEFormElementGetCollection to get a reference by index

The documentation for the function _IEFormElementGetCollection has a specific example of getting a form reference by index.

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

#7 ·  Posted (edited)

As an former (over 5 years ago) VB programmer, I was used to autofill for object methods, etc.

This example:

http://www.autoitscript.com/forum/index.php?showtopic=120300&st=0&p=837041&hl=$oformname&fromsearch=1&entry837041

Shows some use of $oForm.name, $oForm.TagName, et al...

Which I see many other examples out there so there must be a reference I am missing. I have to be honest, I haven't done a ton of searching so I wouldn't be surprised if it is right under my nose. I am just trying to finish this stupid script and it keeps driving me nuts with issues even though I thought it would be easy to do.

Anyway, the other thing is the collections. I am pretty sure I need to use For...In...Next loops and run through all the iterations of the collection.

About indexed instances, that I am not sure is the original issue that you list as an example where it returns a particular index in the function or it returns an object array (collection?) where you would have to iterate through $oForm(1), etc... I am not completely sure.

I tried to find "definitions" for both collections and indexed instances in several autoit tutorials (both web and pdf versions) and although I truly enjoyed the additional learning of autoit, it didn't really help me with the collection/indexed instances issue.

So, with all that said (probably sporatic and poorly) I hope you can figure out what I was trying to explain.

Sorry, long week-end and bad day at work...

Bre

Edited by BreCalmor

Share this post


Link to post
Share on other sites

There are three examples listed for _IEFormGetCollection. I think they do a really good job of explaining both concept and method.

Please look at them carefully and comment again.

Also see the Obj/COM Reference section in the helpfile for more general information.

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

You are absolutely correct, and no doubt there are tons of examples like that. I have not used the _IEFormGetCollection function yet and therefore had not ran across this particular help page. I never doubted there is plenty of information out there.

Thanks for your help and I think I better leave this topic alone until I learn more.

Bre

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