Jump to content

How to get the id and names of a form


Recommended Posts

Hello all,

I am trying to enter some data to an existing web site. after investigating i realized the the form does not have a name. therefore i cannot enter the data automatically,

or identify the input or select field.

in my code i can see the labels but i cannot differentiate between one another.

#include<IE.au3>
#include <Array.au3>
$sURL="http://www.tailor4less.com/en-us/checkout/measures/?step=start"
$oIE=_IECreate($sURL,0, 1, 1, 1)
$colForms = _IEFormGetCollection ($oIE)
For $oForm In $colForms ; loop over form collection

    ConsoleWrite("---- FORM " & $oForm.name & " --------------------" & @CRLF)
    $oFormElements = _IEFormElementGetCollection($oForm) ; get all elements

    For $oFormElement In $oFormElements ; loop over element collection


        If StringLower($oFormElement.tagName) == 'input' Then ; it is an input
            ConsoleWrite("> input." & $oFormElement.type & " " & $oFormElement.name & @CRLF)
            _IEFormElementSetValue($oFormElement, "2", 0) ; set value of the field

        ElseIf StringLower($oFormElement.tagName) == 'textarea' Then ; it is a textarea
            ConsoleWrite("> textarea." & $oFormElement.type & @CRLF)
            _IEFormElementSetValue($oFormElement, "1", 0) ; set value of the field

        ElseIf StringLower($oFormElement.tagName) == 'select' Then ; it is a select
            ConsoleWrite("> select." & $oFormElement.type & @CRLF)
            _IEFormElementOptionSelect($oFormElement,"4")

        EndIf

    Next

Next

 Thanks in advance...

Regards,

source.txt

Capture1.PNG

Link to comment
Share on other sites

$form = _IEFormGetObjByName($oIE, "measure_wizard_form")

$name = _IEFormElementGetObjByName($form, "title")
_IEFormElementSetValue($name, "mikell")

$height = _IEFormElementGetObjByName($form, "feet")
_IEFormElementOptionSelect($height, "6")

_IEFormElementRadioSelect($form, "straight", "param_shoulders")

; etc

:)

Link to comment
Share on other sites

The problem is that these values aren't present in the inputs (source code) because they are internally javascript-generated
so I had a little try in the site to get some more infos :D
... and found the values you're looking for in a json part at the bottom of the page

<script type="text/javascript">ga_callbacks.push(['set','dimension4','wizard_D']);var num_measures_required='7';ga_callbacks.push(['set','dimension6',num_measures_required]);ga_callbacks.push(['set','dimension7','man_jacket']);var options={'region':'en-us','gender':'man','product_type':'','profile':{"next":"1.0","id_shop_customer_profile":"","id_profile_manager":null,"gender":"man","measures_calc":null,"constitution":null,"title":"mikell","height":"180","weight":"80","param_shoulders":"normal","param_abdomen":"normal","param_chest":"normal","param_stance":"normal","body_length":"77.6","sleeves_length":"64.5","shoulders":"48.9","chest":"103.3","stomach":"93.5","hips":"102.1","biceps":"33.6","length_units":"cm","weight_units":"kg","profile_name":"mikell"},etc etc

Then to get the data you must grab the html source and extract them using a nice little regex   ;)

Link to comment
Share on other sites

Hi Mikell, 

i am trying to pull out the JSON file that you motioned.

i tries all bunch of function but none of them are getting me the results i wanted.

i used:

_IEBodyReadHTML, _IEBodyReadText, _IEDocReadHTML, _IEFormGetObjByName.

Link to comment
Share on other sites

This way could be a workaround - sort of

$w = "150"
$h = "6"

$url = "http://www.tailor4less.com/en-us/man/measures/estimate?weight_units=lb&length_units=in&weight=" & $w & "&height=" & $h & _ 
"x&param_stance=normal&param_chest=normal&param_abdomen=normal&param_shoulders=normal&body_length=0&sleeves_length=0&shoulders=0&chest=0&stomach=0&hips=0&biceps=0"

$hr = ObjCreate("WinHttp.WinHttpRequest.5.1")
$hr.Open("GET", $url)
$hr.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20100101 Firefox/14.0.1")
$hr.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
$hr.SetRequestHeader("Referer", "http://www.tailor4less.com/en-us/checkout/measures/?step=measures")
$hr.Send()
If $hr.Status = 200 Then
    $r = $hr.ResponseBody()
    FileWrite("1.txt", $r)
EndIf

 

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