Jump to content

Internet Explorer - Help with form elements and frames


 Share

Recommended Posts

Good Afternoon,

I am trying to create a script to pull up a web browser, navigate to a secure site, log in to the site, navigate within the site requiring clicking on links, and filling out a form.

I am up to the point where I can click a link from within the site, this changes the information in the current frame with that link that I clicked, into a form. I am trying to enter information into the form, but I can't.

Up to this point, I have just been working from the "hotmail.com" login script that I found on this site, but am having issues. Unfortunately up to this point, I have made some coding 'leaps' that I don't understand, but everything up to clicking the link seems to work anyway.

Here is my code, with the sensitive info *'d out.

#include <IE.au3>
 
; Create a browser window and navigate to hotmail
$oIE = _IECreate ("http://www.*.com")
 
$o_form = _IEFormGetCollection ($oIE, 0)
$o_login = _IEFormElementGetObjByName ($o_form, "ssid")
$o_password = _IEFormElementGetObjByName ($o_form, "password")
$o_signin = _IEFormElementGetObjByName ($o_form, "submit")
 
$username = "*"
$password = "*"
 
; Set field values and submit the form
_IEFormElementSetValue ($o_login, $username)
_IEFormElementSetValue ($o_password, $password)
_IEAction ($o_signin, "click")

_IELoadWait($oIE)

; Click the Manage Enrollments link
$oFrame = _IEFrameGetCollection ($oIE, 2)
$LinkName = "Manage Enrollments"
_IELinkClickByText ( $oFrame, $LinkName, 0)

_IELoadWait($oIE)

; Enter ARP111 into the form element "code value" (this is the section that does not work)

$o_CourseName = _IEFormElementGetObjByName ($oIE, "code value")
$CourseCode = "ARP111"
_IEFormElementSetValue ($o_CourseName, $CourseCode)
 
Exit

When I run this, it will log me in to the site, clicks on the 'Manage Enrollments' link in the appropriate frame, and then nothing. I run it from SciTE, and the output bar shows:

C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "*\Desktop\auto it stuffs\IE auto surf.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams

+>13:41:32 Starting AutoIt3Wrapper v.1.9.4

>Running AU3Check (1.54.10.0) from:C:\Program Files\AutoIt3

+>13:41:32 AU3Check ended.rc:0

>Running:(3.2.10.0):C:\Program Files\AutoIt3\autoit3.exe "*\Desktop\auto it stuffs\IE auto surf.au3"

--> IE.au3 V2.3-1 Error from function _IEFormElementGetObjByName, $_IEStatus_InvalidObjectType

--> IE.au3 V2.3-1 Error from function _IEFormElementSetValue, $_IEStatus_InvalidDataType

+>13:41:39 AutoIT3.exe ended.rc:0

This is telling me that my command is not using a correct object type, but since I am completely lost, I just don't know how to continue. Can anyone help me with my issue?
Link to comment
Share on other sites

Thank you for the quick response. I have modified my code to the following:

; Enter ARP111 into the form element "code value"
$oForm = _IEFormGetCollection($oIE,0)
$o_CourseName = _IEFormElementGetObjByName ($oForm, "code value")
$CourseCode = "ARP111"
_IEFormElementSetValue ($o_CourseName, $CourseCode)

but it still does not work. The output from SciTE is:

--> IE.au3 V2.3-1 Warning from function _IEFormGetCollection, $_IEStatus_NoMatch

--> IE.au3 V2.3-1 Error from function _IEFormElementGetObjByName, $_IEStatus_InvalidDataType

--> IE.au3 V2.3-1 Error from function _IEFormElementSetValue, $_IEStatus_InvalidDataType

Link to comment
Share on other sites

Ok... now you need to find out why _IEFormGetCollection is returning $_IEStatus_NoMatch. Have you viewed the generated HTML to verify that a form exists on that web page?

Now you are starting to lose me, sorry for my lack of terminoligy. When you are asking if I have verified the HTML to verify that a form exists, I am not sure what you mean exactly.

I have viewed the HTML, and part of the source code looks like:

<form method=get action="http://www.*/">

<INPUT type=HIDDEN name=_charset_ value="windows-1252">

<input type="hidden" name="CMD" value="GET">

<input type="hidden" name="CMD" value="GET">

<input type="hidden" name="file" value="training_coordinator/classlist/enrollments.jsm">

<INPUT TYPE=HIDDEN NAME=useCookie VALUE="">

<tr><th class="h1" colspan=2><h1>Search enrollments</h1></th></tr>

<!-- ================= Learning Activity Details ====== -->

<tr><th colspan=2 class="h2"><h2>Learning Activity Details</h2></th></tr>

<!-- -------- Code -------- -->

<tr>

<th class="side">Code:</th>

<td><nobr>

<select name="codeSearchOption"><option value="StartsWith" selected>Starts With</option><option value="Exact">Exact</option><option value="Contains">Contains</option></select>

<input type=text size=30 name=code value=''>

</nobr></td>

</tr>

<!-- -------- Title -------- -->

<tr>

<th class="side">Title:</th>

<td><nobr>

<select name="titleSearchOption"><option value="StartsWith" selected>Starts With</option><option value="Exact">Exact</option><option value="Contains">Contains</option></select>

<input type=text size=30 name=title value=''>

</nobr></td>

</tr>

<!-- -------- Type -------- -->

Now, is this the information that tells me if there is a form on the page?

And again, I want to thank you for taking the time to try to help me =.)

Link to comment
Share on other sites

You can easily be surprised by nested frames.

After your _IELoadWait I suggest that you examine the source with ConsoleWrite(_IEDocReadHTML($oIE) & @CR)

You can also download DebugBar and use it to examine the page source and structure (see my signature).

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

You can easily be surprised by nested frames.

After your _IELoadWait I suggest that you examine the source with ConsoleWrite(_IEDocReadHTML($oIE) & @CR)

You can also download DebugBar and use it to examine the page source and structure (see my signature).

Dale

I have added the code to my script. (At first I was like, alright, I added it, but I have no idea where this 'console' is that it will write the information. I have located it in SciTE in the bottom.

<HTML><HEAD><TITLE>*</TITLE><BASE href=http://www.*.com/docent/bin/docentisapi.dll/lms,CGLRWS003,6541/SQN%3D-12651345/></HEAD><FRAMESET border=0 frameSpacing=0 rows=80,* frameBorder=0><FRAME name=banner marginWidth=0 marginHeight=0 src="/docent/lms/banner.html" scrolling=no><FRAMESET border=0 frameBorder=no cols=215,*><FRAME name=menubar src="?CMD=GET&file=menubar.jsm&http_switch=false"><FRAMESET border=0 rows=*,35 frameBorder=no><FRAME name=docent_main src="?CMD=GET&file=instructor/menu_list.jsm"><FRAME name=bottomlogo marginHeight=5 src="/docent/lms/bottomlogo.html" scrolling=no></FRAMESET></FRAMESET></FRAMESET></HTML>

Which as you proably already know, is the same information that I get from the IE-Builder 2 that I got from your signature a while back, and have been experimenting with.

<FRAME name=banner marginWidth=0 marginHeight=0 src="/docent/lms/banner.html" scrolling=no><FRAMESET border=0 frameBorder=no cols=215,*><FRAME name=menubar src="?CMD=GET&file=menubar.jsm&http_switch=false"><FRAMESET border=0 rows=*,35 frameBorder=no><FRAME name=docent_main src="?CMD=GET&file=instructor/menu_list.jsm"><FRAME name=bottomlogo marginHeight=5 src="/docent/lms/bottomlogo.html" scrolling=no></FRAMESET></FRAMESET>

I am trying to get the DebugBar installed right now, but I am on a work computer, and sometimes it is easier said than done.

Now, again, I have to say that I am a complete beginner with HTML stuff, and autoIt. I never created a webpage, and the only AutoIt scripting I did was over a year ago, but all i used as nested for-next loops to scan the monitor, and perform pixelchecksums to compare to a known value.

Having said that, all 'nested frames' means to me is a webpage built from a few different frames, but I have no idea if that is the intened meaning. And now that I have this console information, I really have no idea what it means.

(after self-teaching myself vba with Excel, I was thinking, this stuff is easy, I maybe should change fields to computer programming. Wow, was I sorely mistaken, this stuff is a lot trickier than I would have though, and happy I didn't make the change, or I think I would be doomed.)

Again, thanks for the help. So far you have stopped my brain from exploding.

Link to comment
Share on other sites

Ok, DebugBar installed. And it has helped me a little. First I have amended my code to:

$oForm = _IEFormGetCollection($oIE,0)
$o_CourseName = _IEFormElementGetObjByName ($oForm, "code")
$CourseCode = "ARP111"
_IEFormElementSetValue ($o_CourseName, $CourseCode)

As the name of the element is 'code', not 'code value', as the value I would assume is the value of the box. See, I can be taught a little.

Of course, this has not fixed my issue, it still errors out as before.

Well, I am moving in the right direction I guess.

Is there anyother information I can provide for assistance?

Link to comment
Share on other sites

So look at the source you got back with the ConsoleWrite... there is no FORM is there? But you do see FRAMESET... FRAME.

Check out _IEFrameGetObjByName

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

With DebugBar installed, and looking at the website, it says there are 2 forms on the page I am looking at. (with both named the exact same thing)

Clearly I don't understand.

When I drag and drop the DebugBar 'target thing' into the input box that I want the information from, it does give properties of : <INPUT size=30 name=code>

When I look into the HTML tree that is created by doing this, it does expand the tree under the Document/HTML/.../Frameset branch to highlite the information for me. Now this means that I am dealing with a frame. Ok, I can wrap my head around that.

Now, I keep trying variations of

_IEFrameGetObjByName

and if I use

_IEFrameGetObjByName ($oIE, "docent_main")

I don't know what this does for me.

I was able to fill a form element, I was able to select the right frame, and click a text link, but I just can't wrap my head around this at all. I am sorry for seeming so dense. I just don't know how to tackle this.

Link to comment
Share on other sites

A Frame is actually a Window object that is a container for a document object, The document object in turn contains the forms and other elements. The Frame/Window acts like another browser and you need to drill down to get a reference to it and treat it as you would a browser object (like a $oIE). Does that help? Please test with the helpfile example for _IEFrameGetObjByName.

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

A Frame is actually a Window object that is a container for a document object, The document object in turn contains the forms and other elements. The Frame/Window acts like another browser and you need to drill down to get a reference to it and treat it as you would a browser object (like a $oIE). Does that help? Please test with the helpfile example for _IEFrameGetObjByName.

Dale

Ok, so Frames are each like an independant browser object? In my particular case, the browser I am looking at has few frames, with a banner, a menu, the main area, and the bottom. Each of these frames is its own area, and the one I am interested in, named docent_main is the frame that contains the form that I want to fill out.

To do this, I need to use the _IEFrameGetObjByName function to 'drill' down into the right frame, so I can dig out my form, to fill it out?

I took at look at the help file entry for this command,

#include <IE.au3>
$oIE = _IE_Example ("iframe")
$oFrame = _IEFrameGetObjByName ($oIE, "iFrameTwo")
_IEBodyWriteHTML ($oFrame, "Hello <b>iFrame!</b>")
_IELoadWait ($oFrame)

This has the frame iFrameTwo rewritten with new information.

I don't think this is my case. In my browser, I have 4 or so frames, but in the frame called 'docent_main', there is A LOT of information that can be input. It has over 8 input boxes, 8 pull down boxes, over 20 check boxes...

You have been very patient with me, and I appreciate the effort to help me help myself. I guess I just need a little bit of a further push.

I have a frame named docent_main, it has many input boxes, pull down menus and check boxes that I wish to manipulate. I just don't know how. Sorry =.(

Link to comment
Share on other sites

In your case, you'd select your frame, whatever it is. (Document_main I believe you said). Then you have that frame "object". From their you can grab the forms in that frame with _ieformget*, and get the specific elements of that form with the _ieformelement* functions.

for example:

$oIE = _IEAttach("THIS IS MY SITE")
$oFrame = _IEframegetobjbyname($oIE,"THIS IS THE FRAME NAME")
$oForm = _ieformgetobjbyname($oFrame,"THIS IS THE NAME OF THE FORM")
$oElement = _ieformelementgetobjbyname($oForm,"THIS IS THE ELEMENT TO MANIPULATE")

That is the basic outline. If some of the things don't have names you can get them by index with the *getcollection.

Hope that helps.

Cheers!

Brick

Edited by Brickoneer
Link to comment
Share on other sites

Thank you so much for your help with this. (wow, did I ever need that spelled out for me, thanks Brick)

I finally got it working, well the filling out of the form part. I fill out the form, I submit the form ( the submit button was un-named :) so I used a little for-next loop to find which object it was, turns out it was element 50)

Now, I have used

$oWorkingFrame = _IEFrameGetObjByName ($oIE, "docent_main")
$CUResults = _IEDocReadHTML ($oWorkingFrame)
ClipPut ($CUResults)

to read my information into the clipboard, now I just need to put it into the proper worksheet in Excel. Fun times!

Again, I really appreciate the help you have all given me. I love AutoIt, and the community it has created.

Cheers!

Link to comment
Share on other sites

Is the content in a table? If so, make sure you notice _IETableWriteToArray

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

Is the content in a table? If so, make sure you notice _IETableWriteToArray

Dale

I had a nice piece of code written to use this function, and it worked beautifully. I had to work around the fact that it started at Col 0 because when I used _ExcelWriteSheetFromArray( ) it omitted that column of information. After I ironed that out, _ExcelWriteSheetFromArray( ) function just went really really slow, so I found another way.

I opted for a more straight forward read the HTML data, and paste it directly to excel.

Edit: I can't write a complete thought.

Edited by crambaza
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...