Jump to content
Sign in to follow this  
rudi

Basic help for filling upload form in browser

Recommended Posts

rudi

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!

Share this post


Link to post
Share on other sites
rudi

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!

Share this post


Link to post
Share on other sites
MorganaFreeman

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. 

Share this post


Link to post
Share on other sites
MorganaFreeman

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

 

Share this post


Link to post
Share on other sites
rudi

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!

Share this post


Link to post
Share on other sites
MorganaFreeman

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

 

Share this post


Link to post
Share on other sites
rudi

Yes, thanks.

I read your code several times, I think I got how it has to be done.

 

Have a nice day and thanks again :bye:


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

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  

  • Similar Content

    • seryth
      By seryth
      I have a script that opens some Excel books that  are stored in SharePoint .  Without getting to much into detail as its a very long story I have to open Internet Explorer to the SP site in order for all of this crap to work. 
       
      Anyway I have a bit of code in my script that i found via google-fu
      $ieList = ProcessList("iexplore.exe") If IsArray($ieList) Then For $I = 1 To Ubound($ieList) -1 ProcessWaitClose($ieList[$I][1]) Next EndIf Exit Now on Windows 7 this bit works great.  On Windows Server 2012 R2 where this things runs is another story.  I need to be able to force close all instances of Internet explorer that are running as part of my code. 
       
      Any help is appreciated. 
    • Joro
      By Joro
      Hi,
      I'm struggeling with the following:
      In a website I have to fill in several items. For the normal fields I am able to fill in the information by using UDF "_IEGetObjByName".
      But there is also a dropdown menu and I can't figure out how to choose te right information from it. I have searched the helpfile and the forum but I can't figure it out.
      Here's an excerpt  from the html-page of the site where the dropdown-menu is mentioned:
      <div class="col-md-10 padding-5">
       <div class="btn-group m-r">
        <input type="hidden" name="bedrijfId" class="bedrijfId" value="">
                  <button type="button" data-toggle="dropdown" class="btn btn-sm btn-default dropdown-toggle" >
                       <span class="dropdown-label">Choose Company</span>
                       <span class="caret"></span>
                  </button>
                        <ul class="dropdown-menu dropdown-select" >
                             <li  data-value="2" data-field="bedrijfId"><a href="#"><input type="radio" name="drp1" />Company 1</a></li>
                             <li  data-value="38" data-field="bedrijfId"><a href="#"><input type="radio" name="drp1" />Company 2</a></li>
                             <li  data-value="42" data-field="bedrijfId"><a href="#"><input type="radio" name="drp1" />Company 3</a></li>
                        </ul>
          </div>
      </div>
       
      How do I select one of the companies from the dropdown menu?
      Thanks
      Joost
    • Faraz
      By Faraz
      I have to open a URL on Mozilla Firefox , cursor is by default userid textbox, had to send userid, send tab, send pwd with flag 1 , send tab, send Enter.
      But Script is Failing to take Password.
      Any Help
       
      #include <Constants.au3>
      #include <IE.au3>
      #include <PassMask.au3>
      If $CmdLine[0] <> 3 Then
          MsgBox($MB_OK, "Usage", "ps_weblogin_FireFox <Url> <Browser Title> <Text to Send>")
      Else
         web_login($CmdLine[1], $CmdLine[2], $CmdLine[3])
      EndIf
      Func web_login($bt_url, $bt_Title, $bt_SendText)
          Local $ff = Run("C:\Program Files (x86)\Mozilla Firefox\firefox.exe " & $bt_url)
              WinWaitActive($bt_Title)
          Sleep(2000)
          ControlSend("","","",$bt_SendText)
      EndFunc
      _______________________________________________
      _______________________________________________
      Func Mask_Password($Password)
          $MaskPassword = $Password
          $MaskPassword = StringReplace($MaskPassword, "#", "||||||#@@@@@@")
          $MaskPassword = StringReplace($MaskPassword, "!", "||||||!@@@@@@")
          $MaskPassword = StringReplace($MaskPassword, "+", "||||||+@@@@@@")
          $MaskPassword = StringReplace($MaskPassword, "^", "||||||^@@@@@@")
          $MaskPassword = StringReplace($MaskPassword, "{", "||||||{@@@@@@")
          $MaskPassword = StringReplace($MaskPassword, "}", "||||||}@@@@@@")
          $MaskPassword = StringReplace($MaskPassword, "||||||", "{")
          $MaskPassword = StringReplace($MaskPassword, "@@@@@@", "}")
          Return $MaskPassword
      EndFunc
    • TheWizEd
      By TheWizEd
      It seems AutoIt for Chrome is no longer working.  It's not in Google Store so not able to enable.  I can download the crx and drag to chrome but I can't figure out any way to enable the extension.
    • zxc3
      By zxc3
      Are there any examples of a script for Сhrome that allows you to check whether the information in the browser window has changed with a certain periodicity and signal this for 32-bit Windows.
×