Sign in to follow this  
Followers 0
DenDuze

Problems with submitting form

19 posts in this topic

Hey,

I've made a AutoIt-script that works fine. The only thing that I can't achieve is to submit the form.

I've tried multiple ways to achive this but witout succes.

I've tried:

- _IEFormSubmit

- _IEAction (with just click and also with first focus and then click)

- ControlSend

- first apply entry on control before the submit-button and then a send ("{TAB}") followed by a send("{ENTER}")

None of the above has worked for me.

Is there anyone who knows what I can try or who sees what I'm doing wrong?

Below is the source of the webpage (filtered unneccesary info and Bolded the code that I think is importent)

I'm able to get the fields and set a value in there but I can't submit the form.

I've notices a hidden crc in this source just below the buttons. maybe that's a catcher?

Maybe it's because the "action=" /2012/game1.php" in the post-action

I really don't know (btw I'm not a webdeveloper so I'm not familar with this source/coding

<!DOCTYPE HTML PUBLIC "-//W3C//Dtd HTML 4.01 transitional//EN" "http://www.w3.org/tr/html4/loose.dtd">

<html>

<head>

<title>.....</title>

<meta http-equiv=Content-Type content="text/html; charset=iso-8859-1">

<meta content="MSHTML 6.00.2900.3243" name=GENERATOR>

<link rel="shortcut icon" href="icon.gif">

</head>

<body text=#000000 vLink=#000099 aLink=#000099 link=#000099 bgColor=#ffffff>

<table borderColor=#ffffff height=768 width=907 bgColor=#ffffff border=3>

<tbody>

<tr>

<td vAlign=top align=right width="4%" bgColor=#ffffff>&nbsp;</td>

<td vAlign=top width="96%" background=../bkground.jpg

bgColor=#999966>

<table borderColor=#ffffff width="100%" border=1>

<tbody>

<tr>

<td borderColor=#ffffff width="25%" bgColor=#ffffff height=64><IMG

height=65 src="...."

width=857></td>

</tr></tbody></table>

<table borderColor=#009900 width="100%" border=1>

<tbody>

<tr bgColor=#000000>

<td width="6%" bgColor=#000000>

<div align=center><font color=#000000><b><font color=#ffffff><a

href="../index.htm"><font

color=#cccccc>Home</font></a></font></b></font></div></td>

<td width="20%">

<div align=center><font color=#ffffff><b><a

href="../overzicht.htm"><font

color=#cccccc>Overzicht wedstrijden</font></a></b></font></div></td>

<td width="13%">

<div align=center><font color=#ffffff><b><a

href="../rangschikking.htm"><font

color=#cccccc>Rangschikking</font></a></b></font></div></td>

<td width="13%" bgColor=#000000>

<div align=center><font color=#ffffff><b><a

href="../inschrijving.htm"><font

color=#cccccc>Schrijf je in</font></a></b></font></div></td>

<td width="11%">

<div align=center><font color=#ffffff><b><a

href="...." target=_blank><font

color=#cccccc>Forum</font></a></b></font></div></td>

<td width="24%">

<div align=center><font color=#ffffff><b><a

href="../reglement.htm"><font

color=#cccccc>Wedstrijdreglement</font></a></b></font></div></td>

<td width="13%">

<div align=center><font color=#ffffff><b><a

href="../contact.htm"><font

color=#cccccc>Contact</font></a></b></font></div></td></tr></tbody></table>

<p>&nbsp;</p>

<p><b><font color=#003300 size=5>Game 1</font></b></p>

<p><b>Waar:</b> The Side Game @ Trivial</p>

.....

<h1>Inschrijving:</h1>

<form method="post" name="send" action=" /2012/game1.php ">

<table width="auto">

<tr>

<td width="110px" style="text-align:right;">Naam</td>

<td class="left"><input name="naam" type="text" size="27"/></td>

</tr>

....

<tr>

<td width="94%" colspan="2" style="text-align:center;">

<input type="submit" value="Verzend" name="verzenden" />

&nbsp;

<input type="reset" value="Wis alles" name="reset" />

<input type="hidden" name="crc" value="6ea48a53c6579e199c5218f7d1fca6b3f35a6a48" />

</td>

</tr>

</table>

</form>

......

</tbody>

</table>

<p>&nbsp;</p>

<p>&nbsp;</p></td></tr>

</tbody>

</table>

</BODY>

</HTML>

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi,

the methods you described should work, no offense but it is more likely you did something wrong, please post some code so we can where the problem lies.

; method 1 - using the _IEForm* funcs
$oForm, _IEFormGetCollection($oIE, 0)
_IEFormSubmit($oForm)

;method 2 - clicking submit
$oForm, _IEGetObjByName($oIE, 'send', 0)
$oSubmit = _IEGetObjByName($oForm, 'verzenden')
_IEAction($oSubmit, 'click')

Edit: When you post code put it in some [ code ]....[ /code ] or [ autoit ]....[ /autoit ] tags

Edited by Robjong

Share this post


Link to post
Share on other sites

Thanks for the reaction.

What I'm trying:

There is a webpage where on a specific date & hour some fields come available.

I want to open that page, refresh the page until the fields come available

Fill the fields with data from an ini-file

submit the form

reopen that page and fill in the fields again with other data (and so one, if needed)

This is the code that I have until now:

Remember: the TEST-blocks are the different things I've tries to submit the form (so only one of those is in my actual code)

#include <IE.au3>

; Get the needed values from ini-file
$year   = IniRead("FDP.ini","MAIN","year","2012")
$game   = IniRead("FDP.ini","MAIN","game","1")
$site   = IniRead("FDP.ini","MAIN","site","")
$players = IniReadSection("FDP.ini","PLAYERS")
$msgFlag = 262144 ; top-most

$i     = 0
$result  = 0
$femail  = 0
$mail   = ""
$url     = $site


$IE = _IECreate($url)

Do
    ; STEP 1: the page gets refreshed until the fields are available => when femail <> 0 then the fields are available
    ;        (default the fields are not on the page! On a specific moment they come available!
    while $femail = 0  ; failure = 0
        sleep(2000) ; 2 seconds waiting between refreshes (not needed ...)
        _IEAction($IE,"refresh")
        _IELoadWait($IE) ; wait until refresh is completed
        
        $form =_IEFormGetObjByName ($IE,"Send") ; This is the name of the submit-button of the webpage
        
        $fnaam     = _IEGetObjByName($IE,"naam")
        $ftag       = _IEGetObjByName($IE,"tag")
        $fwoonplaats = _IEGetObjByName($IE,"woonplaats")
        $femail   = _IEGetObjByName($IE,"email")
        $fsubmit     = _IEGetObjByName($IE,"Verzenden")
    WEnd
    
    ; STEP 2: for each player out the ini-file do the following
    While 1 ; loop, use ExitLoop when needed
        $i += 1
        $tmp   = StringSplit($players[$i][1],",") ; enkel de waarde speelt een rol, de key niet!
        $name  = $tmp[1]
        $tag   = $tmp[2]
        $city  = $tmp[3]
        $mail  = $tmp[4]
    
        ; msgbox($msgflag,"test gegevens", "naam: " & $name & " - " & "tag: " & $tag & " - " & "city: " & $city & " - " & "mail: " & $mail)
        
        ; STEP 2A: Fill the fields with the data from the ini-file + submit the form
        Do
            _IEFormElementSetValue($fnaam,$name)
            _IEFormElementSetValue($ftag,$tag)
            _IEFormElementSetValue($fwoonplaats,$city)
            _IEFormElementSetValue($femail,$mail)
            
            [b];< here I tried multiple sollutions
            ;TEST 1 (I think that this is the correct one - but it doesn't work?)
            IEFormSubmit($form)
            _IELoadWait($IE) ; wait untill submit is done
            
            ;TEST 2 (put focus on the submit-button en perform a click)
             $result = _IEAction($fsubmit, "focus")
             $result = _IEAction ($fsubmit, "click")
            
            ;TEST 3 (some example I found on the Net)
            $hwnd = _IEPropertyGet($IE, "hwnd")
            _IEAction ($fsubmit, "focus")
         ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")

            ;TEST 4 (put focus on field before the submit-button - apply TAB and ENTER
            $result = _IEAction($femail, "focus")
         Send ("{TAB}")
            send({ENTER})
        
            ;TEST 5 (is the same as a previous test but first I change the value of that submit-button to check if I have the correct handle
            ;         => the label of the button changes correctly but the click doesn't submits the form?
            $Form = _IEFormGetObjByName($IE, "send")
            $fsubmit = _IEFormElementGetObjByName ($Form, "Verzenden")
            _IEFormElementSetValue($fsubmit,"Hey! It works!")
            $result = _IEAction($fsubmit, "click")[/b]
        
            $result = 1 ; leave this block => players-data is submitted
        until $result = 1 ; 1 = success */
    
        _IENavigate($IE,$url) ; restart the webpage to process the next player
        $femail = 0
        ExitLoop
    WEnd
    ;Until 1 = 1 ; $i = $players[0][0] ; dit is het aantal lijnen in deze sectie
; dezelfde controle om programma te verlaten - want moet altijd waarde voor invulvelden ook vernieuwe bij de loop
Until $i = $players[0][0] ; dit is het aantal lijnen in deze sectie

_IEQuit ($IE) ; close browser

Share this post


Link to post
Share on other sites

Can you perhaps share the URL to the page?

The HTML you provided should work with _IEFormSubmit, no problem.

From looking at your script it seems more likely the script does not exit the first while loop and never gets to the submit part.

Try this modified version of your script and see if the MsgBox pops up, Opt("TrayIconDebug", 1) is there so you can check where the scipt is by hovering over the tray icon.

#include <IE.au3>


AutoItSetOption("TrayIconDebug", 1) ; this is so we can see where the script is at by hovering over the tray icon


; Get the needed values from ini-file
$year = IniRead("FDP.ini", "MAIN", "year", "2012")
$game = IniRead("FDP.ini", "MAIN", "game", "1")
$site = IniRead("FDP.ini", "MAIN", "site", "")
$players = IniReadSection("FDP.ini", "PLAYERS")
$msgFlag = 262144 ; top-most

$i = 0
$result = 0
$femail = 0
$mail = ""
$url = $site


;~ $IE = _IECreate("file://" & @ScriptDir & "foo_904738.html")
$IE = _IECreate($url)
Do
    ; STEP 1: the page gets refreshed until the fields are available => when femail <> 0 then the fields are available
    ;       (default the fields are not on the page! On a specific moment they come available!
    While 1 ; $femail == 0 ; failure = 0
        Sleep(2000) ; 2 seconds waiting between refreshes (not needed ...)

        _IEAction($IE, "refresh")
        _IELoadWait($IE) ; wait until refresh is completed

        $form = _IEFormGetObjByName($IE, "Send") ; This is the name of the submit-button of the webpage

        ; while this returns 0 the loop continues
        $femail = _IEGetObjByName($form, "email")
        If Not @error Then ; check if we found the email field
            ConsoleWrite("+> field 'email' found" & @CRLF)
            $fnaam = _IEGetObjByName($form, "naam") ; use $form instead of $IE
            $ftag = _IEGetObjByName($form, "tag")
            $fwoonplaats = _IEGetObjByName($form, "woonplaats")
            $fsubmit = _IEGetObjByName($form, "Verzenden")
            ExitLoop ; break out this loop
        EndIf

        ConsoleWrite("!> field 'email' not found" & @CRLF)
    WEnd

    ; this is just to check if the script ever breaks out the first while loop
    MsgBox(0, 'Test', 'Email field found, now filling and submitting form')

    ; STEP 2: for each player out the ini-file do the following
    While 1 ; loop, use ExitLoop when needed
        $i += 1
        $tmp = StringSplit($players[$i][1], ",") ; enkel de waarde speelt een rol, de key niet!
        $name = $tmp[1]
        $tag = $tmp[2]
        $city = $tmp[3]
        $mail = $tmp[4]

        ; msgbox($msgflag,"test gegevens", "naam: " & $name & " - " & "tag: " & $tag & " - " & "city: " & $city & " - " & "mail: " & $mail)
        ConsoleWrite(StringFormat("%02d", $i) & "  naam: " & $name & " - " & "tag: " & $tag & " - " & "city: " & $city & " - " & "mail: " & $mail & @CRLF)

        ; STEP 2A: Fill the fields with the data from the ini-file + submit the form
        Do
            _IEFormElementSetValue($fnaam, $name)
            _IEFormElementSetValue($ftag, $tag)
            _IEFormElementSetValue($fwoonplaats, $city)
            _IEFormElementSetValue($femail, $mail)

            ; submit form
            _IEFormSubmit($form)
            If Not @error Then $result = 1
            _IELoadWait($IE) ; wait untill submit is done

;~             $result = 1 ; leave this block => players-data is submitted
        Until $result == 1 ; 1 = success */

        _IENavigate($IE, $url) ; restart the webpage to process the next player
        $femail = 0
        ExitLoop
    WEnd
    ;Until 1 = 1 ; $i = $players[0][0] ; dit is het aantal lijnen in deze sectie
    ; dezelfde controle om programma te verlaten - waarden voor invulvelden ook vernieuwen bij de loop
Until $i == $players[0][0] ; dit is het aantal lijnen in deze sectie

_IEQuit($IE) ; close browser

Share this post


Link to post
Share on other sites

Ok, thanks Spammer I will try this but I'm sure that the script executes the submit.

I've put multiple messages @testing but I erased those when I put my code in this topic

Share this post


Link to post
Share on other sites

Please re-read the forum rules! I get the impression that you try some kind of game automation.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

It is not a game automation.

it's to register myself (and son) for repeating events.

This way I don't have to refresh all the time and type the same data all over again.

If this is not allowed on this forum I'm sorry that I've created this topic (but I see no reason why this is not allowed)

Share this post


Link to post
Share on other sites

The word "game" is always a trigger in every post asking for help.

But sometimes this is a problem too: "SPAM tools including instant messenger or forum auto-posters. This includes forum or site auto-login methods."

This might not be the case for your situation but please check the rules so you are on the save side :)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

@Spammer: Thanks for the modified code but it still doesn't work.

I get the value -1 back from the _IEformsubmit (= Succes) so everything is fine ecxept that the form isn't submitted.

I leave the fields empty and run the script so normally I must get a validation error but I don't get that one (I get ik when I click om the button)

Share this post


Link to post
Share on other sites

With so much Javascript behind most form prosessing these days, I am surprised when a simple submit action ever works. Take a look at the second example for _IEAction in the helpfile.

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

Hey Dale,

I've also tried that one but still no go

Share this post


Link to post
Share on other sites

"no go" won't get you any more help. Show your code and describe what happens or better yet, post a reproducer.

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

My code is posted (see a previous post in this topic)

There is even an modified code but with the same result.

I've noticed that when my cursor hovers over the submit button that I get a tooltip.

Can it be that the submit depends on that tooltip?

Share this post


Link to post
Share on other sites

That might be, but without the URL to the page there is no way to be sure.

You did not post a working example/reproducer of the problem, the code you did post (HTML/AutoIt) do not show the problem you described, the actual page will likely have javascript etc. that cause this behaviour.

Share this post


Link to post
Share on other sites

Hey guy, if you are using IE9 without having turned on COMPATIBILITY mode then form submit doesn't work. The only way I could make it work was with compatibility mode on or IE 8 or before. Something to do with the way IE9 processes forms differently to previous versions.

Share this post


Link to post
Share on other sites

IE??

I use FireFox (can that be the problem?

I've got it to work!

I now use a stupid MouseClick (with coordinates).

I know that this is not the way to do it but it works and as I looked @ the webpage the positioning of the buttons are always the same so as far as I know this will keep working (it is not an elegant way to do it but it does what it has to do)

Thanks everybody for trying to help

Share this post


Link to post
Share on other sites

IE??

I use FireFox (can that be the problem?

Using _IE* functions to interact with Firefox might prove problematic.

Good thing you mention it and the end of your thread, haha.

Share this post


Link to post
Share on other sites

Yes, maybe I've should have mentioned that before but does this mean that all the _IE functions are only made for IE?

I think that many people work with FireFox so what type of AutoIt-coding is best to use with FireFox?

Are there better ways then the _IE functions??

Most of them seem to work but as I noticed some of them don't

Share this post


Link to post
Share on other sites

_IE functions are for Internet Explorer only! If you use FireFox you need to have a look at the _FF functions


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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