Jump to content

Basic help for filling upload form in browser


rudi
 Share

Recommended Posts

Hello,

usually I do Win automations, so I have no skills at all to handle HTML forms :-/

The script to catch and syntax check  the required information from Excel is done.

Now I'd like to automate the upload using this form, too:

 

http://flashcardsdeluxe.com/flashcards/Upload.aspx

  • What browser is easiest to do so? (IE, Chrome, FF)
  • The Values $DeckCode, $DeckName, $DeckDefinition shall go to their HTML form fields
  • finally "click" the button "upload flashcards"
<table width="70%" class="cssCenter" border="0">

        <tr>
        <td style="width: 1%">Deck&nbsp;Code</td>
        <td style="width: 100%"><input name="ctlDeckCode" type="text" id="ctlDeckCode" style="width:50%;" /> (no spaces allowed)</td>
        <td></td>
        </tr>
        
        <tr>
        <td style="width: 1%">Deck&nbsp;Name</td>
        <td style="width: 100%"><input name="ctlDeckName" type="text" id="ctlDeckName" style="width:50%;" /> (optional)</td>
        <td style="width: 1%" align="right"><input type="submit" name="ctlUpload" value="Upload Flashcards" id="ctlUpload" /></td>
        </tr>
            
        <tr>
        <td valign="top" style="padding-top: 5px" >Flashcard&nbsp;Text</td>
        <td colspan="2"><textarea name="ctlFlashcardText" rows="2" cols="20" id="ctlFlashcardText" style="height:280px;width:100%;"></textarea></td>
        </tr>
    </table>

If someone kindly could jump in showing how to address just one of the input fields and how to "click" the "upload flashcards" button, I should be able to do the rest myself.

TIA, Rudi.

UploadFlashCards.jpg

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

Hello,

 

This code is opening the right web page, but does *NOT* fill the "form elements" as I would expect:

 

#include <ie.au3>

$URL="http://flashcardsdeluxe.com/flashcards/Upload.aspx"
$DeckCode="SpanischDeck01Basic"
$Deckname="Spanisch Deck01, Grundwortschatz"



$NameDeckCode="ctlDeckCode"
$NameDeckName="ctlDeckName"
$NameFCText="ctlFlashcardText"





$oFCUP=_IECreate($Url,0,1,1,1)
$FormElementDeckCode=_IEFormElementGetObjByName($oFCUP,$NameDeckCode)
_IEFormElementSetValue($FormElementDeckCode,$DeckCode)

$FormElementDeckName=_IEFormElementGetObjByName($oFCUP,$NameDeckName)
_IEFormElementSetValue($FormElementDeckName,$Deckname)

I've installed Autoit v3.3.14.2 and the latest Beta, to try to use IE_Builder2.0.1 (IE-library_v2.0.1.exe) -- hm. Looks like a really huge tool, but I'm too stupid to use it. :-//

 

Regards. Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

Well, I'm pretty new to autoit, but you could try it like that : 

I think the problem with your code is, that you don't declare the form you want to fill. 

<form name="form1" method="post" action="Upload.aspx" id="form1">

This is the form, taken from the html of your homepage

 

Now you can try it like this (didn't test it) : 

 


 

$URL="http://flashcardsdeluxe.com/flashcards/Upload.aspx"

$DeckCode="SpanischDeck01Basic"

$Deckname="Spanisch Deck01, Grundwortschatz" 

$NameDeckCode="ctlDeckCode" 

$NameDeckName="ctlDeckName"

$NameFCText="ctlFlashcardText"





Do
    $oIE = _IECreate($Url,0,1,1,1)
Until IsObj($oIE)



   $oForm = _IEGetObjById($oIE, "form1")       ;you need this to declare the form you want to fill. the form ID is form1 as you can see in the html code


    $oCode = _IEFormElementGetObjByName($oForm, $NameDeckCode) 
    _IEFormElementSetValue($oCode, $DeckCode) 



    $oName = _IEFormElementGetObjByName($oForm, $NameDeckName) 
    _IEFormElementSetValue($oName, $Deckname) 

 

The problem with your code is here : 

 

$FormElementDeckCode=_IEFormElementGetObjByName($oFCUP,$NameDeckCode)

because you directly adress the IE instead of the form. 

 

I hope I could help. 

Link to comment
Share on other sites

Here a short (tested and working) example on how also click the button : 

 

#include <ie.au3>


;Declare Variables=============================================

$URL="http://flashcardsdeluxe.com/flashcards/Upload.aspx"

$DeckCode="SpanischDeck01Basic"

$Deckname="Spanisch Deck01, Grundwortschatz"

$NameDeckCode="ctlDeckCode"

$NameDeckName="ctlDeckName"

$NameFCText="ctlFlashcardText"

$FcText = "You can use a InputBox or GUI to fill this text"

;===============================================================




Do
    $oIE = _IECreate($Url,0,1,1,1)
Until IsObj($oIE)


_Fill_Name_Code() ;We call the Func


Func _Fill_Name_Code()

   $oForm = _IEGetObjById($oIE, "form1")       ;you need this to declare the form you want to fill. the form ID is form1 as you can see in the html code


    $oCode = _IEFormElementGetObjByName($oForm, $NameDeckCode)
    _IEFormElementSetValue($oCode, $DeckCode)



    $oName = _IEFormElementGetObjByName($oForm, $NameDeckName)
    _IEFormElementSetValue($oName, $Deckname)

    _Fill_Flashcard_Text()

EndFunc



Func _Fill_Flashcard_Text()

    $oForm = _IEGetObjById($oIE, "form1")

    $oText = _IEFormElementGetObjByName($oForm, $NameFCText)
    _IEFormElementSetValue($oText, $FcText)



    _Click_Upload()



EndFunc



Func _Click_Upload()

$oButtons = _IETagnameGetCollection($oIE, "input")
For $oButton in $oButtons
    If String($oButton.value) = "Upload Flashcards" Then
        _IEAction($oButton, "click")
        ExitLoop
    EndIf
Next

EndFunc

 

Link to comment
Share on other sites

Hi.

Thanks for your replies.

At a glance I didn't get everything, but I'm sure you've pointed me the right direction :D:D

On my way to get familiar with IE.AU3 ...

 

Regards, Rudi.

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

Let's say it like that :

 

Each website has it's forms in which the inputs etc. are. 

 

You've created an instance of IE with following code 

$oFCUP=_IECreate($Url,0,1,1,1)

And then you tried to fill the input for the Deck Code with this :

$FormElementDeckCode=_IEFormElementGetObjByName($oFCUP,$NameDeckCode)
_IEFormElementSetValue($FormElementDeckCode,$DeckCode)

You use the code _IEFormElementGetObjByName, so you want to get an FORM element. But you didn't declare the form, you tried to get the Form element straight out of the IE (as you can see at the first parameter, you used the variable for your IE instance there).

 

That's why it didn't work.

 

If you take a deeper look into my code you'll understand it

 

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

×
×
  • Create New...