Jump to content

Need help getting a specific form on webpage using IE8


Recommended Posts

Hi, Thanks in advance for any assistance anyone can provide.

My issue should be a simple one. I am working on a front end to help me manage my affiliate accounts.

On one of the affiliate sites I deal with, I come to a page with 4 forms on it. Each form has a submit button named submit. Of course if I use something like:

$var = _IEFormGetObjByName($oIE, "submit")

I receive the first form's submit on the page. I have attempted getting the form collection and various ways to manipulate that to attempt to get form1's submit button and must be overlooking something.

I have a secondary form I am working on some error checking once the form is submitted, but am stuck on how to parse the text on the page for the following words that come up in green if the form was filled out correctly. Words in green: Submitted Successfully.

Thanks again for any assistance.

Link to comment
Share on other sites

Try

$oForm = _IEFormGetCollection($oIE, 1)
$var = _IEFormGetObjByName($oForm, "submit")
to access the first form on your webpage.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Try

$oForm = _IEFormGetCollection($oIE, 1)
$var = _IEFormGetObjByName($oForm, "submit")
to access the first form on your webpage.

Ok, I have given this code a try before as well and just attempted again. However, allow me to clarify that this is actually the 4th form on the page. The first is frmlogin, the second frmrecpswd, the third 0 and the 4th form1.

I used the above code but when I choose to _IEAction($var, "click") it has no effect. Here is my code:

The other 2 variables are data returns from the database.

$oIE = _IECreate("http://" & $affil & $dom)
_IELoadWait($oIE)
$oForm = _IEFormGetCollection($oIE, 4)
$Submit = _IEFormGetObjByName($oForm, "submit")
_IEAction($Submit, "click")

Again nothing happens, the browser stops on the page with the forms.

Here is the code I used to collect the form information:

$oForms = _IEFormGetCollection($oIE)
Local $iNumForms = @extended
MsgBox(0, "Forms Info", "There are " & $iNumForms & " forms on this page")
For $i = 0 To $iNumForms - 1
$oForm = _IEFormGetCollection($oIE, $i)
MsgBox(0, "Form Info", $oForm.name)
Next
Edited by Daymond
Link to comment
Share on other sites

I would suggest do add at least some minimal error checking:

$oIE = _IECreate("http://" & $affil & $dom)
ConsoleWrite(@error & @CRLF)
_IELoadWait($oIE)
ConsoleWrite(@error & @CRLF)
$oForm = _IEFormGetCollection($oIE, 4)
ConsoleWrite(@error & @CRLF)
$Submit = _IEFormGetObjByName($oForm, "submit")
ConsoleWrite(@error & @CRLF)
_IEAction($Submit, "click")
ConsoleWrite(@error & @CRLF)
What do you get?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I would suggest do add at least some minimal error checking:

$oIE = _IECreate("http://" & $affil & $dom)
ConsoleWrite(@error & @CRLF)
_IELoadWait($oIE)
ConsoleWrite(@error & @CRLF)
$oForm = _IEFormGetCollection($oIE, 4)
ConsoleWrite(@error & @CRLF)
$Submit = _IEFormGetObjByName($oForm, "submit")
ConsoleWrite(@error & @CRLF)
_IEAction($Submit, "click")
ConsoleWrite(@error & @CRLF)
What do you get?

I get the following:

--> IE.au3 V2.4-0 Warning from function _IEFormGetCollection, $_IEStatus_NoMatch

7

--> IE.au3 V2.4-0 Error from function _IEFormGetObjByName, $_IEStatus_InvalidDataType

3

--> IE.au3 V2.4-0 Error from function _IEAction, $_IEStatus_InvalidDataType

3

Link to comment
Share on other sites

Seems like the instance index starts with 0. So replace

$oForm = _IEFormGetCollection($oIE, 4)
with
$oForm = _IEFormGetCollection($oIE, 3)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Seems like the instance index starts with 0. So replace

$oForm = _IEFormGetCollection($oIE, 4)
with
$oForm = _IEFormGetCollection($oIE, 3)

Yeah, tried that, then 2, then 1 and even 0. I get the same results.
Link to comment
Share on other sites

Another try. This should write the number of forms to the console as well:

$oIE = _IECreate("http://" & $affil & $dom)
ConsoleWrite(@error & @CRLF)
_IELoadWait($oIE)
ConsoleWrite(@error & @CRLF)
$oForm = _IEFormGetCollection($oIE, -1)
ConsoleWrite(@error & "-" & @extended & @CRLF)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Mmmh,

you may also have a look on the form element and use something like:

$oDiv = _IEFormElementGetObjByName ($oForm ,"submit")

_IEAction ($oDiv,"click")

HTH, Reinhard

Strange, with the minimal error checking set, I receive the follwoing when I try that code:

--> IE.au3 V2.4-0 Warning from function _IEFormElementGetObjByName, $_IEStatus_NoMatch

7

--> IE.au3 V2.4-0 Error from function _IEAction, $_IEStatus_InvalidDataType

3

0

Link to comment
Share on other sites

Taken from the source of the page I am working in, stripped down of course.

<form id="frm1" name="form1" method="post" action="securesignup_choosecountry.asp">
 
<input type="hidden" Name="UserName" Value="Daymond">
<input type="submit" name="Submit" value="Continue" onclick="javascript:window.onbeforeunload = null;return checkform(event);">
                      </p>
                    </form>
Link to comment
Share on other sites

One word. Frames.

If you

ConsoleWrite(_IEDocReadHTML($oIE) & @CRLF)

I think you will find a frameset or one or more iframes and not your forms.

You'll then need to use _IEFrameGetObjByName() and use the object returned as you would $oIE.

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

One word. Frames.

If you

ConsoleWrite(_IEDocReadHTML($oIE) & @CRLF)

I think you will find a frameset or one or more iframes and not your forms.

You'll then need to use _IEFrameGetObjByName() and use the object returned as you would $oIE.

Dale

Thanks Dale, but as it turns out, with IE9 I was able to use the following 2 lines of code to solve the issue, but it still fails on Windows XP with IE8.

$Sub = _IEGetObjByName($oIE, "form1")
_IEFormSubmit($Sub)

I still have a couple of other snags I need to work through and am sure I will be posting more questions. lol

Thanks everyone for the assistance!

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...