Jump to content

Recommended Posts

Posted

Hi,

I'm trying to select an item in a dropdown box but when I submit the form, seems like the item is not selected although it appeared in the box.

Here is the html code of the form:

<input type="hidden" id="pstad-loctnid" name="postAdForm.locationId" value="80002"/>
    <li>
        <a name="postAdForm.location"></a>
        <label for="locationLevel0" class="add-asterisk">Ville&nbsp;:</label>
        <div class="form-section">
            <select id="locationLevel0" name="locationLevel0" req="req" class="locationSelector ">
                <option value="">----------</option>
                <option value="1700278">
                    Laval / Rive-Nord</option>
                <option value="1700279">
                    Longueuil / Rive-Sud</option>
                <option value="1700280">
                    Ouest de l'île</option>
                <option value="1700281">
                    Ville de Montréal</option>
            </select>
            <div class="field-message" data-for="locationLevel0"></div>
            <p class="message">Veuillez sélectionner votre emplacement ou un lieu près de chez vous.</p>
        </div>
    </li>
;

And here is the script code I'm using:

Sleep(1000)
$oIEDoc = $oIE.Document
$oIEBody = $oIEDoc.body
$selects = $oIEBody.GetElementsByTagname("select")
$numofselects = $selects.length
For $r = 0 To $numofinputs - 1
    $myobj = $selects.item($r)
    If $myobj.id = "locationLevel0" And $myobj.name="locationLevel0" Then
        _IEAction($myobj, "focus")
        $myobj.value = "1700281"
        ExitLoop
    EndIf
Next
;

The "Ville de Montréal" option appears in the box but when I submit the form, I get a message that it's missing this information.

Please tell me what I'm doing wrong.

Thanks

Posted (edited)

Try putting $myobj.value = "1700281" before the "focus" and changing "focus" to "click".

If that doesn't work add a "click" after the "focus"

Edited by Dent
Posted (edited)

Try this:

#include <IE.au3>

; REMARK:
; Before you run this script you should copy HTML snippet to Clipboard

_Example()
Func _Example()
    Local $oIE = _IECreate()
    _IEDocWriteHTML($oIE, ClipGet())

    Local $oIE_Select = _IEGetObjById($oIE, 'locationLevel0')
    _IEFormElementOptionSelect($oIE_Select, '1700281', 1, "byValue")
EndFunc   ;==>_Example

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Sorry mLipok,

Tried you solution, it does the same as my original scrtipt.

It does selects the  "Ville de Montréal" option that appears in the box but when I submit the form, I get a message that it's missing this information again.

Will try Dent's solution...

Posted
_IEFormElementOptionSelect($oIE_Select, '1700281', 1, "byValue", 0)

?

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Sorry mLipok,

Tried you solution, it does the same as my original scrtipt.

It does selects the  "Ville de Montréal" option that appears in the box but when I submit the form, I get a message that it's missing this information again.

Will try Dent's solution...

1-Open_New_form.jpg

2-After_Script.jpg

3-After_Submit.jpg

4-Dropdown_List.jpg

Posted

Tried adding the ", 0" at the end of the line and it does the same thing.

Added the form's photos before, during and after submit...

Posted

Dent, sorry but it does the same as my original script.

It does changes the selection box from "--------" to "Ville de Montréal" but we I click submit, the form returns with the same filled form and a top section

showing a message stating to correct errors on the page and lower it says "You have not finished filling the form".

5-Error_Msg.jpg

Posted

After the submit and the return of the form with the error message, the dropdown selection box is back to "--------" as if nothing was ever selected.

 

Posted

An here is the full script to test the form.

While the script starts entering fields, scroll down mid page to see the city selection of "Ville de Montréal".

After the script ends, click on the button: "Afficher votre annonce".

You should get the page coming back filled with the error and the city being back to "--------".

Posted

Oops, here's bthe code:

;======================================================================================
#include <IE.au3>
#include <MsgBoxConstants.au3>
Global $oIE = _IECreate ("http://www.kijiji.ca/h-grand-montreal/80002", 0, 1, 1)
Opt ("SendKeyDelay", 100)
Local $hWnd = WinWait($oIE, "", 5) ; Wait 5 seconds for the window to appear.1
WinSetState(_IEPropertyGet($oIE, "hwnd"), "", @SW_MAXIMIZE)
;======================================================================================
; AFFICHER UNE ANNONCE
;======================================================================================
Sleep(1000)
$oIEDoc  = $oIE.Document
$oIEBody = $oIEDoc.body
$oDiv1 = _IEGetObjById($oIE, "PostAdLink")
_IEAction($oDiv1, "click")
;======================================================================================
; Catégorie CHAMBRES À LOUER, COLOCS
;======================================================================================
Sleep(1000)
$oIEDoc  = $oIE.Document
$oIEBody = $oIEDoc.body
$oDiv2 = _IEGetObjById($oIE, "CategoryId37")
_IEAction($oDiv2, "click")
;======================================================================================
; Nombre de pièces
;======================================================================================
Sleep(1000)
$oIEDoc  = $oIE.Document
$oIEBody = $oIEDoc.body
_IELinkClickByText($oIE, "4 1/2")
;======================================================================================
; PRIX
;======================================================================================
Sleep(1000)
$oIEDoc = $oIE.Document
$oIEBody = $oIEDoc.body
$inputs = $oIEBody.GetElementsByTagname("input")
$numofinputs = $inputs.length
For $r = 0 To $numofinputs - 1
    $myobj = $inputs.item($r)
    If $myobj.id = "priceAmount" And $myobj.type="text" Then
        $myobj.value="100.00"
        ExitLoop
    EndIf
Next
;======================================================================================
; Propriéraire
;======================================================================================
Sleep(1000)
$oIEDoc = $oIE.Document
$oIEBody = $oIEDoc.body
$inputs = $oIEBody.GetElementsByTagname("input")
$numofinputs = $inputs.length
For $r = 0 To $numofinputs - 1
    $myobj = $inputs.item($r)
    If $myobj.id = "forrentbyhousing_s" And $myobj.value="ownr" Then
        _IEAction($myobj, "click")
        ExitLoop
    EndIf
Next
;======================================================================================
; Nombre de salles de bain
;======================================================================================
Sleep(1000)
$oIEDoc = $oIE.Document
$oIEBody = $oIEDoc.body
$selects = $oIEBody.GetElementsByTagname("select")
$numofselects = $selects.length
For $r = 0 To $numofinputs - 1
    $myobj = $selects.item($r)
    If $myobj.name = "postAdForm.attributeMap[numberbathrooms_s]" And $myobj.id="numberbathrooms_s" Then
        $myobj.value = "10"
        ExitLoop
    EndIf
Next
;======================================================================================
; Meublé
;======================================================================================
Sleep(1000)
$oIEDoc = $oIE.Document
$oIEBody = $oIEDoc.body
$inputs = $oIEBody.GetElementsByTagname("input")
$numofinputs = $inputs.length
For $r = 0 To $numofinputs - 1
    $myobj = $inputs.item($r)
    If $myobj.id = "furnished_s" And $myobj.value="1" Then
        _IEAction($myobj, "click")
        ExitLoop
    EndIf
Next
;======================================================================================
; Animaux
;======================================================================================
Sleep(1000)
$oIEDoc = $oIE.Document
$oIEBody = $oIEDoc.body
$inputs = $oIEBody.GetElementsByTagname("input")
$numofinputs = $inputs.length
For $r = 0 To $numofinputs - 1
    $myobj = $inputs.item($r)
    If $myobj.id = "petsallowed_s" And $myobj.value="0" Then
        _IEAction($myobj, "click")
        ExitLoop
    EndIf
Next
;======================================================================================
; Titre
;======================================================================================
Sleep(1000)
$oIEDoc = $oIE.Document
$oIEBody = $oIEDoc.body
$inputs = $oIEBody.GetElementsByTagname("input")
$numofinputs = $inputs.length
For $r = 0 To $numofinputs - 1
    $myobj = $inputs.item($r)
    If $myobj.id = "postad-title" And $myobj.type="text" Then
        $myobj.value="Test-01"
        ExitLoop
    EndIf
Next
;======================================================================================
; Description
;======================================================================================
Sleep(1000)
$oIEDoc = $oIE.Document
$oIEBody = $oIEDoc.body
$textareas = $oIEBody.GetElementsByTagname("textarea")
$numoftextareas = $inputs.length
For $r = 0 To $numoftextareas - 1
    $myobj = $textareas.item($r)
    If $myobj.id = "pstad-descrptn" And $myobj.name="postAdForm.description" Then
        $myobj.value="Test-02 with minimum 10 chars"
        ExitLoop
    EndIf
Next
;======================================================================================
; Code postal
;======================================================================================
Sleep(1000)
$oIEDoc = $oIE.Document
$oIEBody = $oIEDoc.body
$inputs = $oIEBody.GetElementsByTagname("input")
$numofinputs = $inputs.length
For $r = 0 To $numofinputs - 1
    $myobj = $inputs.item($r)
    If $myobj.id = "addressPostalCode" And $myobj.type="text" Then
        $myobj.value="H1A1A1"
        ExitLoop
    EndIf
Next
;======================================================================================
; Lieu
;======================================================================================
Sleep(1000)
$oIEDoc = $oIE.Document
$oIEBody = $oIEDoc.body
$inputs = $oIEBody.GetElementsByTagname("input")
$numofinputs = $inputs.length
For $r = 0 To $numofinputs - 1
    $myobj = $inputs.item($r)
    If $myobj.id = "AddressCity" And $myobj.type="text" Then
        $myobj.value="Test-03"
        ExitLoop
    EndIf
Next
;======================================================================================
; Ville
;======================================================================================
Sleep(1000)
$oIEDoc = $oIE.Document
$oIEBody = $oIEDoc.body
$selects = $oIEBody.GetElementsByTagname("select")
$numofselects = $selects.length
For $r = 0 To $numofinputs - 1
    $myobj = $selects.item($r)
    If $myobj.id = "locationLevel0" And $myobj.name="locationLevel0" Then
        $myobj.value = "1700281"
        _IEAction($myobj, "focus")
        $myobj.value = "1700281"
        ExitLoop
    EndIf
Next
;======================================================================================
; Téléphone
;======================================================================================
Sleep(1000)
$oIEDoc = $oIE.Document
$oIEBody = $oIEDoc.body
$inputs = $oIEBody.GetElementsByTagname("input")
$numofinputs = $inputs.length
For $r = 0 To $numofinputs - 1
    $myobj = $inputs.item($r)
    If $myobj.id = "PhoneNumber" And $myobj.type="text" Then
        $myobj.value="555-555-5555"
        ExitLoop
    EndIf
Next
;======================================================================================

 

Posted

I made some changes. After i click in the button "Afficher votre annonce" its giving me another error "Une erreur est survenue lors de l'affichage de votre annonce. Veuillez contact le Service à la clientèle." probably because we are filling the form with "test" data. Try to fill with the correct data to see if its correct.

;======================================================================================
#include <IE.au3>
#include <MsgBoxConstants.au3>

Local $oIE = _IECreate ("https://www.kijiji.ca/p-post-ad.html?categoryId=214")
;~ Opt ("SendKeyDelay", 100)
Local $hWnd = WinWait($oIE, "", 5) ; Wait 5 seconds for the window to appear.1
WinSetState(_IEPropertyGet($oIE, "hwnd"), "", @SW_MAXIMIZE)
;======================================================================================
; AFFICHER UNE ANNONCE
;======================================================================================
$oANNONCE = _IEGetObjById($oIE, "PagePostAsOwner")
_IEAction($oANNONCE, "click")
_IELoadWait($oIE)
Sleep(5000) ; just to make sure
;======================================================================================
; PRIX
;======================================================================================
Local $oPrix = _IEGetObjById($oIE, "priceAmount")
_IEFormElementSetValue($oPrix, "100.00")
;======================================================================================
; Propriéraire
;======================================================================================
Local $oForm = _IEFormGetObjByName($oIE, "PostAdMainForm")
_IEFormElementRadioSelect($oForm, "ownr", "forrentbyhousing_s")
;======================================================================================
; Nombre de salles de bain
;======================================================================================
Local $oN_Salles_de_bain   = _IEGetObjById($oIE, "numberbathrooms_s")
_IEFormElementOptionSelect($oN_Salles_de_bain, "10")
;======================================================================================
; Meublé
;======================================================================================
_IEFormElementRadioSelect($oForm, "1", "furnished_s")
;======================================================================================
; Animaux
;======================================================================================
_IEFormElementRadioSelect($oForm, "0", "petsallowed_s")
;======================================================================================
; Titre
;======================================================================================
Local $oTitre = _IEGetObjById($oIE, "postad-title")
_IEFormElementSetValue($oTitre, "Test-01")
;======================================================================================
; Description
;======================================================================================
Local $oDescription = _IEGetObjById($oIE, "pstad-descrptn")
_IEFormElementSetValue($oDescription, "Test-02 with minimum 10 chars")
;======================================================================================
; Code postal
;======================================================================================
Local $oCodePostal = _IEGetObjById($oIE, "addressPostalCode")
_IEFormElementSetValue($oCodePostal, "H1A1A1")
;======================================================================================
; Lieu
;======================================================================================
Local $oLieu = _IEGetObjById($oIE, "AddressCity")
_IEFormElementSetValue($oLieu, "Test-03")
;======================================================================================
; Ville
;======================================================================================
Local $oVille  = _IEGetObjById($oIE, "locationLevel0")
_IEFormElementOptionSelect($oVille, "1700281")
Local $oVilleHidden = _IEGetObjById($oIE, "pstad-loctnid")
_IEFormElementSetValue($oVilleHidden, "1700281")
;======================================================================================
; Téléphone
;======================================================================================
Local $oTelephone = _IEGetObjById($oIE, "PhoneNumber")
_IEFormElementSetValue($oTelephone, "555-555-5555")
;======================================================================================
; Adresse de courriel
;======================================================================================
Local $oEmail = _IEGetObjById($oIE, "pstad-email")
_IEFormElementSetValue($oEmail, "test@test1.com")
;======================================================================================

Exit

The script its smaller and faster. :)

Posted

MichaelHB,

you found my solution with :

input type="hidden" id="pstad-loctnid" which I overlooked.

The script you wrote works fine as it is. 

I do not get the error :   error "Une erreur est survenue lors de l'affichage de votre annonce. Veuillez contact le Service à la clientèle." 

Thanks very much for your precious help.

GerryIT

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...