CT83

AutoIt Runtime (The requested action with this object has failed)

13 posts in this topic

I send Pushbullet Updates (pushbullet.com) of my script using its native API and i have the following code to do the same, but in some cases my internet connection sometimes stops responding and the notification can't be send  using HTTP.send($sPD) methods,in such cases due to the lack of internet connection a runtime error (The requested action with this object has failed) is generated! This creates problems, as the stability of my script is affected. Is there a way to solve this problem?

Func Send_Pushbullet($spTitle,$sBody,$GFPsh_Tk)
Local $sPD = '{"type": "note", "title": "'&$spTitle&'","body": "'&$sBody&'"}'
$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("POST", "https://api.pushbullet.com/v2/pushes", False)
$oHTTP.setRequestHeader("Authorization", "Bearer " & $GFPsh_Tk)
$oHTTP.SetRequestHeader("Content-Type", "application/json")
$oHTTP.Send($sPD)
$Result = $oHTTP.ResponseText
ToolTip2("PushBullet :"&$Result)
ToolTip2("PushBullet Sent - "&$spTitle&" : "&$sBody&" "&$GFPsh_Tk)
EndFunc

 

Share this post


Link to post
Share on other sites



Yes. Check the return value and @error of each $oHTTP method call and only process the next step when there was no error.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Just now, water said:

Yes. Check the return value and @error of each $oHTTP method call and only process the next step when there was no error.

okay, i think u are saying something on the lines of "If @error Then" if i am not mistaken, right? so where should i add these error handling statements ? after http.open ? http.send() ? or after obj create as described in the help file? or is this code right?

Func Send_Pushbullet($spTitle,$sBody,$GFPsh_Tk)
Local $sPD = '{"type": "note", "title": "'&$spTitle&'","body": "'&$sBody&'"}'
$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
If Not @error Then
$oHTTP.Open("POST", "https://api.pushbullet.com/v2/pushes", False)
$oHTTP.setRequestHeader("Authorization", "Bearer " & $GFPsh_Tk)
$oHTTP.SetRequestHeader("Content-Type", "application/json")
$oHTTP.Send($sPD)
$Result = $oHTTP.ResponseText
ToolTip2("PushBullet :"&$Result)
ToolTip2("PushBullet Sent - "&$spTitle&" : "&$sBody&" "&$GFPsh_Tk)
Else
ConsoleWrite("Ie error")
EndIf   
EndFunc

 

Share this post


Link to post
Share on other sites

Something like this. It exits after an error and displays a MsgBox:

Func Send_Pushbullet($spTitle, $sBody, $GFPsh_Tk)
    
    Local $sPD = '{"type": "note", "title": "' & $spTitle & '","body": "' & $sBody & '"}'
    $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
    If @error Then Exit MsgBox(0, "Error", "ObjCreate returned @error = " & @error & " and @extended = " & @extended)
    $oHTTP.Open("POST", "https://api.pushbullet.com/v2/pushes", False)
    If @error Then Exit MsgBox(0, "Error", "Open method returned @error = " & @error & " and @extended = " & @extended)
    $oHTTP.setRequestHeader("Authorization", "Bearer " & $GFPsh_Tk)
    If @error Then Exit MsgBox(0, "Error", "SetRequestHeader method returned @error = " & @error & " and @extended = " & @extended)
    $oHTTP.SetRequestHeader("Content-Type", "application/json")
    If @error Then Exit MsgBox(0, "Error", "SetRequestHeader method returned @error = " & @error & " and @extended = " & @extended)
    $oHTTP.Send($sPD)
    If @error Then Exit MsgBox(0, "Error", "Send method returned @error = " & @error & " and @extended = " & @extended)
    $Result = $oHTTP.ResponseText
    ToolTip2("PushBullet :" & $Result)
    ToolTip2("PushBullet Sent - " & $spTitle & " : " & $sBody & " " & $GFPsh_Tk)

EndFunc   ;==>Send_Pushbullet

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
6 minutes ago, water said:

Something like this. It exits after an error and displays a MsgBox:

Func Send_Pushbullet($spTitle, $sBody, $GFPsh_Tk)
    
    Local $sPD = '{"type": "note", "title": "' & $spTitle & '","body": "' & $sBody & '"}'
    $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
    If @error Then Exit MsgBox(0, "Error", "ObjCreate returned @error = " & @error & " and @extended = " & @extended)
    $oHTTP.Open("POST", "https://api.pushbullet.com/v2/pushes", False)
    If @error Then Exit MsgBox(0, "Error", "Open method returned @error = " & @error & " and @extended = " & @extended)
    $oHTTP.setRequestHeader("Authorization", "Bearer " & $GFPsh_Tk)
    If @error Then Exit MsgBox(0, "Error", "SetRequestHeader method returned @error = " & @error & " and @extended = " & @extended)
    $oHTTP.SetRequestHeader("Content-Type", "application/json")
    If @error Then Exit MsgBox(0, "Error", "SetRequestHeader method returned @error = " & @error & " and @extended = " & @extended)
    $oHTTP.Send($sPD)
    If @error Then Exit MsgBox(0, "Error", "Send method returned @error = " & @error & " and @extended = " & @extended)
    $Result = $oHTTP.ResponseText
    ToolTip2("PushBullet :" & $Result)
    ToolTip2("PushBullet Sent - " & $spTitle & " : " & $sBody & " " & $GFPsh_Tk)

EndFunc   ;==>Send_Pushbullet

 

oh okay!  thanks alot! that was all i needed!

Share this post


Link to post
Share on other sites

Could you please just "Reply to this topic" without quoting the whole post? Makes your thread easier to read and saves a lot of space. And I know what I posted before ;)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

BTW: If you run AutoIt > 3.3.12.0 then you need to add a COM error handler as suggested by Jos above. Else your script will always crash when a COM error is being detected.
Check the help file for ObjEvent and you will find an example.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Okay sure i will try that... gimme a sec

Edited by CT83

Share this post


Link to post
Share on other sites

yeah, i looked up in the help file, but i failed to understand how it works, I am a real beginner :(could u please illustrate the same with my example? or anything similar? 

I am not trying to get you to do my work, its just that i dont really get the example in the helpfile. Sorry for inconvenice :( 

-newbie 

Share this post


Link to post
Share on other sites

Quite easy:

Func Send_Pushbullet($spTitle, $sBody, $GFPsh_Tk)
    
    ; Error monitoring. This will trap all COM errors while alive.
    ; This particular object is declared as local, meaning after the function returns it will not exist.
    Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")
    Local $sPD = '{"type": "note", "title": "' & $spTitle & '","body": "' & $sBody & '"}'
    $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
    If @error Then Exit MsgBox(0, "Error", "ObjCreate returned @error = " & @error & " and @extended = " & @extended)
    $oHTTP.Open("POST", "https://api.pushbullet.com/v2/pushes", False)
    If @error Then Exit MsgBox(0, "Error", "Open method returned @error = " & @error & " and @extended = " & @extended)
    $oHTTP.setRequestHeader("Authorization", "Bearer " & $GFPsh_Tk)
    If @error Then Exit MsgBox(0, "Error", "SetRequestHeader method returned @error = " & @error & " and @extended = " & @extended)
    $oHTTP.SetRequestHeader("Content-Type", "application/json")
    If @error Then Exit MsgBox(0, "Error", "SetRequestHeader method returned @error = " & @error & " and @extended = " & @extended)
    $oHTTP.Send($sPD)
    If @error Then Exit MsgBox(0, "Error", "Send method returned @error = " & @error & " and @extended = " & @extended)
    $Result = $oHTTP.ResponseText
    ToolTip2("PushBullet :" & $Result)
    ToolTip2("PushBullet Sent - " & $spTitle & " : " & $sBody & " " & $GFPsh_Tk)

EndFunc   ;==>Send_Pushbullet

; User's COM error function. Will be called if COM error occurs
Func _ErrFunc($oError)
    ; Do anything here.
    ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
$oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

Okay!!! Finally got it! Declare this (code) as Global at the top of my script. Then add a MsgBox and stuff in _ErrFunc ! right! o:)

Thanks all. You are awesome! :lmao:

Share this post


Link to post
Share on other sites

Ops. Copy & Paste error in my post. I missed to post this line :(


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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

  • Similar Content

    • Patryk
      By Patryk
      Dear Colleagues,
      I have no idea how to refer to style.display in my loop. There is a button like: 
      <input name="ctl00$bodyPlaceholder$btnFecharProcessamento" class="button" id="bodyPlaceholder_btnFecharProcessamento" style="display: none;" onclick="FecharJanelaProcessamento();return false;" type="submit" value="Fechar"> I want it to be clicked as soon as button's style change from style="display: none;" to  style= ="display: inline-block;" 
      This is what I got, but it's not working...
      Func GetButtons() $oButtons = _IEGetObjByName($oForm,"ctl00$bodyPlaceholder$btnFecharProcessamento",-1) $i = 0 While $i <> 1 For $oBtn In $oButtons If _IEFormElementGetValue($oBtn) = "Fechar" And $oBtn.document.style.display = "display: inline-block;" Then $i = 1 _IEAction($oBtn, "focus") _IEAction($oBtn, "click") ExitLoop EndIf Next WEnd EndFunc  
      I will really appreciate if you could help me with these loop!
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      Before all, I want to say that I'm doing this script to see how _IE* functions work, and see if my studs can hack a quiz I'm working on.
      I want to clarify that I'm not automating any game, bypassing any CAPTCHAs, or anything that could damage anyone.
      I was trying to autofill a form, based on which question is displayed.
      The question is always stored in here:
      <header> <h1><span class="questionid">1. </span>Here goes the question</h1> </header> And answers are stored in here:
      <ul class="answers"> <li><label><span><input id="answer_0" name="answer[]" type="radio" value="0">Answer 1</span></label></li> <li><label><span><input id="answer_1" name="answer[]" type="radio" value="1">Answer 2</span></label></li> <li><label><span><input id="answer_2" name="answer[]" type="radio" value="2">Anwser 3</span></label></li> <li><label><span><input id="answer_3" name="answer[]" type="radio" value="3">Answer 4</span></label></li> </ul></fieldset></form></div> And, there are 15 questions like this.
      How can automatically fill my form?
      Thanks in advance
      Francesco
    • Omnitica
      By Omnitica
      Hello!
      I'm new to the forums! Couldn't find any threads covering this issue. Sorry if I'm wrong.

      I'm having problems changing the text/value of a input box. The particular box doesn't have a name or id, just: class="jq_hotkeys_enabled form-control".
      This class appears multiple times throughout the source, so I don't think It's right to reference that object. 
      See image 1.
      However, I've managed to find a object with the name "ctl00$content$ctrl$ucServiceTime$rpServicetimes$ctl00$edtHiddenResourceHelper" which contains the value of the input box, and the id for the person in the dropdown/combobox left of it. (with "dummy-1" selected).
      See image 2.
      As you can see the value is 3982,4545     ( name , time )
      But when I try to change the value of it by doing:
      #include <IE.au3> Local $oIE = _IEAttach(WinGetHandle("[CLASS:IEFrame]"),"embedded") Local $oForm = _IEFormGetObjByName($oIE, "aspnetForm") Local $oInput = _IEFormElementGetObjByName($oForm, "ctl00$content$ctrl$ucServiceTime$rpServicetimes$ctl00$edtHiddenResourceHelper") _IEFormElementSetValue($oInput, "3982,1337") The box doesn't get its new value. I  can see in the source that it's changed though.
      See image 3.
       
      However, if I do: 
      #include <IE.au3> Local $oIE = _IEAttach(WinGetHandle("[CLASS:IEFrame]"),"embedded") Local $oForm = _IEFormGetObjByName($oIE, "aspnetForm") Local $oInput = _IEFormElementGetObjByName($oForm, "ctl00$content$ctrl$ucServiceTime$rpServicetimes$ctl00$edtHiddenResourceHelper") _IEFormElementSetValue($oInput, "3982,1337") $oIE.document.parentwindow.execScript("theForm.submit()") ; But it needs to reload the page The box gets its new value after the page reloads by the theForm.submit() function. 
      This is a bit unfortunate as I want the changes to happen instantly like when I type in the box with the keyboard... or select in the combobox.
      Maybe someone knows how I can do this? Looking forward to an answer! 
      Thanks in advance.
       
      Note: Unfortunately I can't provide with the real URL as it is constricted to employees in the company I work for, but let me know If I should provide anything else.
       



    • ur
      By ur
      For the below form, I am able to automate using below code for textboxes.

      #include <IE.au3> Local $oIE = _IEAttach("http://localhost:18170/MartAdmin/", "url") _IELoadWait($oIE) $Search = _IEGetObjById($oIE,"x-auto-16-input") _IEPropertySet($Search, 'innerText','Uday KIran') $Search = _IEGetObjById($oIE,"x-auto-18-input") _IEPropertySet($Search, 'innerText','Uday KIran') But for the Login button, there is no id or name.
      The html code when I click on Inspect element in browser, shown below.
      <button tabindex="0" class="x-btn-text" style="width: 64px; position: relative;" type="button">Log In</button> Please let me know how to click this.?
       
    • jonson1986
      By jonson1986
      Hey,
      I'm trying to select language from drop-down menu on a webpage by _IEGetObjById but it's  not working, It mean autoit open the page but unable to select my desired value not even by matching text or by value, I'm looking for kind help...I've pastes my Autoit codes below along with source codes(using ie) of the webpage ;
      #include <IE.au3> $site = "http://example.com/upload" $oIE = _IECreate($site) $oDownloadSamples = _IEGetObjById($oIE, "language") $oDownloadSamplesSelect = _IETagNameGetCollection($oDownloadSamples, "select", "language") $oDownloadSamplesSelect.focus _IEFormElementOptionSelect($oDownloadSamplesSelect, "French", 1, "byText") Sleep (1000) _IEFormElementOptionSelect($oDownloadSamplesSelect, "2", 1, "byValue") HTML Codes using IE:
      <html> <head> <div class="form-row"> <div class="col-7"> <label>Language</label> <select name="language" class="select" id="language"> <option value="1">English</option> <option value="2">French</option> <option value="3">German</option> <option value="4">Italian</option> <option value="5">Japanese</option> <option value="6">Spanish</option> <option value="7">Russian</option> <option value="8">Hindi</option> <option value="9">Arabic</option> <option value="10">Chinese</option> <option value="11">Dutch</option> <option value="12">Finnish</option> <option value="13">Korean</option> <option value="14">Norwegian</option> <option value="15">Portuguese</option> <option value="16">Romanian</option> <option value="17">Serbian</option> <option value="18">Croatian</option> <option value="20">Polish</option> <option value="21">Afar</option> <option value="22">Abkhazian</option> <option value="23">Afrikaans</option> <option value="24">Amharic</option> <option value="25">Assamese</option> <option value="26">Aymara</option> <option value="27">Azerbaijani</option> <option value="28">Bashkir</option> <option value="29">Belarusian</option> <option value="30">Bulgarian</option> <option value="31">Bihari</option> <option value="32">Bislama</option> <option value="33">Bengali/Bangla</option> <option value="34">Tibetan</option> <option value="35">Breton</option> <option value="36">Catalan</option> <option value="37">Corsican</option> <option value="38">Czech</option> <option value="39">Welsh</option> <option value="40">Danish</option> <option value="41">Bhutani</option> <option value="42">Greek</option> <option value="43">Esperanto</option> <option value="44">Estonian</option> <option value="45">Basque</option> <option value="46">Persian</option> <option value="47">Fiji</option> <option value="48">Faeroese</option> <option value="49">Frisian</option> <option value="50">Irish</option> <option value="51">Scots/Gaelic</option> <option value="52">Galician</option> <option value="53">Guarani</option> <option value="54">Gujarati</option> <option value="55">Hausa</option> <option value="56">Hungarian</option> <option value="57">Armenian</option> <option value="58">Interlingua</option> <option value="59">Interlingue</option> <option value="60">Inupiak</option> <option value="61">Indonesian</option> <option value="62">Icelandic</option> <option value="63">Hebrew</option> <option value="64">Yiddish</option> <option value="65">Javanese</option> <option value="66">Georgian</option> <option value="67">Kazakh</option> <option value="68">Greenlandic</option> <option value="69">Cambodian</option> <option value="70">Kannada</option> <option value="71">Kashmiri</option> <option value="72">Kurdish</option> <option value="73">Kirghiz</option> <option value="74">Latin</option> <option value="75">Lingala</option> <option value="76">Laothian</option> <option value="77">Lithuanian</option> <option value="78">Latvian/Lettish</option> <option value="79">Malagasy</option> <option value="80">Maori</option> <option value="81">Macedonian</option> <option value="82">Malayalam</option> <option value="83">Mongolian</option> <option value="84">Moldavian</option> <option value="85">Marathi</option> <option value="86">Malay</option> <option value="87">Maltese</option> <option value="88">Burmese</option> <option value="89">Nauru</option> <option value="90">Nepali</option> <option value="91">Occitan</option> <option value="92">(Afan)/Oromoor/Oriya</option> <option value="93">Punjabi</option> <option value="94">Pashto/Pushto</option> <option value="95">Quechua</option> <option value="96">Rhaeto-Romance</option> <option value="97">Kirundi</option> <option value="98">Kinyarwanda</option> <option value="99">Sanskrit</option> <option value="100">Sindhi</option> <option value="101">Sangro</option> <option value="102">Serbo-Croatian</option> <option value="103">Singhalese</option> <option value="104">Slovak</option> <option value="105">Slovenian</option> <option value="106">Samoan</option> <option value="107">Shona</option> <option value="108">Somali</option> <option value="109">Albanian</option> <option value="110">Siswati</option> <option value="111">Sesotho</option> <option value="112">Sundanese</option> <option value="113">Swedish</option> <option value="114">Swahili</option> <option value="115">Tamil</option> <option value="116">Telugu</option> <option value="117">Tajik</option> <option value="118">Thai</option> <option value="119">Tigrinya</option> <option value="120">Turkmen</option> <option value="121">Tagalog</option> <option value="122">Setswana</option> <option value="123">Tonga</option> <option value="124">Turkish</option> <option value="125">Tsonga</option> <option value="126">Tatar</option> <option value="127">Twi</option> <option value="128">Ukrainian</option> <option value="129">Urdu</option> <option value="130">Uzbek</option> <option value="131">Vietnamese</option> <option value="132">Volapuk</option> <option value="133">Wolof</option> <option value="134">Xhosa</option> <option value="135">Yoruba</option> <option value="136">Zulu</option> <option value="19">Other</option> </select> </div> </main> </body> </html>