CemalSenturk Posted January 10, 2015 Author Share Posted January 10, 2015 (edited) Can someone please find a solution to my problem? Code is above. Edited January 10, 2015 by CemalSenturk Link to comment Share on other sites More sharing options...
CemalSenturk Posted January 13, 2015 Author Share Posted January 13, 2015 Why does nobody answer? I need your help guys. Please help me finish it Here is the code again. I want to click a button with multiple forms on a page. #include <IE.au3> SignIn() DoStuff() SignOut() Func SignIn() Local $oIE, $oForm, $oText, $oForms $oIE = _IECreate ("http://www.car.gr/classifieds/tractors/edit/5934835/#details") $oForm = _IEFormGetCollection ($oIE, 1) $oText = _IEFormElementGetObjByName($oForm, "password") _IEFormElementSetValue($oText, "---") _IEFormSubmit($oForm) EndFunc Func DoStuff() Local $oIE, $oDiv, $oForm Local $oDiv = _IEGetObjById($oIE, "details") $oForm = _IETagNameGetCollection($oDiv, "form", 0) _IEFormSubmit($oForm) EndFunc Func SignOut() If IsObj($oIE) Then _IEQuit($oIE) EndIf EndFunc This code clicks the wrong button. Button which deletes the advertisement. I tried: $oForm = _IETagNameGetCollection($oDiv, "form", 1) $oForm = _IETagNameGetCollection($oDiv, "form", 2) Instead of: $oForm = _IETagNameGetCollection($oDiv, "form", 0) But no. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 13, 2015 Moderators Share Posted January 13, 2015 (edited) Why does nobody answer? Because we're not being paid to be on your demanding schedule? 3 problems for me to help. 1. I seriously have no clue what you're trying to do (step by step). 2. You say you're running IE11, what update version are you running (the version and KB update)? 3. I have no access to the page you're talking about to even warrant putting in time to help. Edited January 13, 2015 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
CemalSenturk Posted January 14, 2015 Author Share Posted January 14, 2015 (edited) SmOke_N Thank you so much for answer My goal is, login to my account on this site and click to one button to save changes with advertisement (want to run the script every day 2-3 times) and I want to automate it with script. There are two ways to login. 1st way is to login from here http://www.car.gr/users/login/ , type username and password then navigate to the details page. 2nd way is directly create details page (http://www.car.gr/classifieds/edit/?cid=5934835#details), type password and you are at the details page. I use 2. way and have two buttons on details page. One button returns to the homepage and second one is the button that I want to click it. Source: expandcollapse popup<div class="tab-content"> <div class="tab-pane active" id="delete"> <h2>Delete</h2> <form id="delete_form" action="/classifieds/tractors/delete/5929826/" method="post"> <input type="checkbox"> <button type="submit" class="btn btn-danger" disabled="disabled"> <i class="fa fa-trash-o"> ::before</i> </button> </form> </div> <div class="tab-pane" id="photos">...</div> <div class="tab-pane active" id="details"> <h2>Details></h2> <form class="form-horizontal" action="/classifieds/tractors/edit/5121406/#details" method="post"> <input name="dealer_id" type="hidden" value=""></input> <fieldset>...</fieldset> <fieldset>...</fieldset> <fieldset>...</fieldset> <fieldset>...</fieldset> <fieldset>...</fieldset> <fieldset>...</fieldset> <fieldset>...</fieldset> <fieldset>...</fieldset> <p class="alert alert-warning"</p> <fieldset>...</fieldset> <div class="form-actions"> <button class="btn btn-primary" type="submit">Save Changes</button> </div> </form> </div> <div class="tab-pane" id="statistics">...</div> <div class="tab-pane" id="reports">...</div> <div class="tab-pane" id="trading">...</div> <div class="tab-pane" id="preview">...</div> </div> Button is named Save Changes. Thank you so much! IE Version: 11.0.9600.17358 Update Versions: 11.0.13 (KB2987107) Edited January 14, 2015 by CemalSenturk Link to comment Share on other sites More sharing options...
Moderators Solution SmOke_N Posted January 14, 2015 Moderators Solution Share Posted January 14, 2015 (edited) Please understand, not being able to access that page, I won't help to debug. The _IEJS_GetObjByClassArray is going to return an array, it will also be included in my internet explorer extension to IE.au3 ... >IEJS.au3 ... seriously thinking I'm going to change that to just IEEx.au3 because there are as many reg funcs now as there are javascript ones. expandcollapse popup#include <IE.au3> Global $goIE = 0 Global $gsURL = "http://www.car.gr/classifieds/tractors/edit/5934835/#details" Global $gsPassword = "MyPasswordHere" _Login($goIE, $gsPassword, $gsURL) If @error Then Exit @error + _IEQuit($goIE) - 1 EndIf ; do the stuff on the edit page you're going to do ; stuff ; stuff ; etc ; submit the form _mySubmitSavePage($goIE) Func _mySubmitSavePage(ByRef $oObj) If Not IsObj($oObj) Then Return SetError(1, 0, 0) EndIf Local $aoForm = _IEJS_GetObjByClassArray($oObj, "form-horizontal", "form") If Not IsArray($aoForm) Then Return SetError(2, 0, 0) EndIf Local $oForm = $aoForm[0] ; get the form from the array _IEFormSubmit($oForm) If @error Then Return SetError(3, 0, 0) EndIf ; wait for rendering to start Sleep(2000) ; wait for page to load _IELoadWait($oObj) If @error Then Return SetError(4, 0, 0) EndIf Return 1 EndFunc Func _Login(ByRef $oObj, $sPassword, $sURL) If Not IsObj($oObj) Then $oObj = _IECreate($sURL) If Not IsObj($oObj) Then Return SetError(1, 0, 0) EndIf _IELoadWait($oObj) EndIf Local $aoForm = _IEJS_GetObjByClassArray($oObj, "form-horizontal", "form") If Not IsArray($aoForm) Then Return SetError(2, 0, 0) EndIf Local $oForm = $aoForm[0] ; get the form from the array Local $oPass = _IEGetObjByName($oForm, "password", 0); first instance only If Not IsObj($oPass) Then Return SetError(3, 0, 0) EndIf _IEFormElementSetValue($oPass, $gsPassword) ; login _IEFormSubmit($oForm) If @error Then Return SetError(4, 0, 0) EndIf ; wait for rendering to start Sleep(2000) ; wait for page to load _IELoadWait($oObj) If @error Then Return SetError(5, 0, 0) EndIf Return 1 EndFunc Func _IEJS_GetObjByClassArray(ByRef $oObj, $sClass, $sTag = Default, $iIndex = -1) ; returns an array of objects If Not IsObj($oObj) Then Return SetError($_IESTATUS_InvalidDataType, 1, 0) EndIf $iIndex = (IsKeyword($iIndex) Or $iIndex < 0) ? -1 : $iIndex $sTag = (IsKeyword($sTag) Or Not StringLen($sTag)) ? "" : $sTag Local $oTags = (StringLen($sTag)) ? _IETagNameGetCollection($oObj, $sTag, $iIndex) : _ _IETagNameAllGetCollection($oObj, $iIndex) Local $iExtended = @extended If Not IsObj($oTags) Then Return SetError($_IESTATUS_NoMatch, 2, 0) EndIf Local $aRet[$iExtended], $iCount If $iIndex = -1 Then For $oTag In $oTags If String($oTag.classname) = $sClass Then $aRet[$iCount] = $oTag $iCount += 1 EndIf Next Else $aRet[$iCount] = $oTags.index($iIndex) If Not IsObj($aRet[$iCount]) Then Return SetError($_IESTATUS_InvalidValue, 3, 0) EndIf $iCount += 1 EndIf If Not $iCount Then Return SetError($_IESTATUS_NoMatch, 4, 0) EndIf ReDim $aRet[$iCount] Return SetError($_IESTATUS_Success, 1, $aRet) EndFunc Good luck. Edited January 14, 2015 by SmOke_N CemalSenturk and Gianni 2 Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
CemalSenturk Posted January 15, 2015 Author Share Posted January 15, 2015 Oh man thank you so much. It works fine. Thank you so much! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now