Jump to content

FF.au3 - Controlling the flow of asynchronous (i.e. AJAX) site


Go to solution Solved by jdelaney,

Recommended Posts

I'm trying to automate Zendesk, an AJAX based helpdesk platform, and am having trouble controlling the flow of the script due to the asynchronous nature of the site. Functions that normally help with this kind of thing such as FFLoadWait or IsObj aren't applicable here and I'm looking for guidance or tips from the community since I'm sure I'm not the first person to run up against this problem. At the moment, I'm getting by on Sleep statements but know this is an awful way to do things from an efficiency standpoint. Does anyone have any tips on ways to control the flow when working with asynchronous sites where elements that appear to be forms are dynamically generated?

Here's a sample of some of the generated source I'm working with -- note: all of these ID's are dynamic and change from ticket to ticket etc.

<div class="ember-view" id="ember860">
      <div id="alert" class="ember-view"><p>
  <b><span id="i18n-0">Zendesk Alert:</span></b>
  <script id="metamorph-0-start" type="text/x-placeholder"></script><script id="metamorph-0-end" type="text/x-placeholder"></script>
  <script id="metamorph-1-start" type="text/x-placeholder"></script><script id="metamorph-1-end" type="text/x-placeholder"></script>
</p>
<script id="metamorph-2-start" type="text/x-placeholder"></script><script id="metamorph-2-end" type="text/x-placeholder"></script>
<a class="close" data-ember-action="1" tabindex="-1">×</a>
</div>
      <div id="wrapper" class="ember-view os-windows filters">
        <header id="branding_header" class="ember-view split_pane">
  <ul id="tabs" class="ember-view column"><li id="ember1447" class="ember-view tab add"><span class="icon"></span><span><span id="i18n-23">add</span></span>
<div style="; display: none;" class="popover add bottom">
  <div class="popover-inner">
    <h3 class="popover-title"><span id="i18n-24">New…</span></h3>
    <div class="popover-content">
      <button id="ember1456" class="ember-view" type="button">
        <span id="i18n-25">Ticket</span>
      </button>

      <button id="ember1461" class="ember-view" type="button">
        <span id="i18n-26">User</span>
      </button>

      <button id="ember1462" class="ember-view" style="display:none;" type="button">
        <span id="i18n-27">Organization</span>
      </button>

      <h3 class="popover-title popover-content-title"><span id="i18n-28">Recently viewed tickets…</span></h3>
      <div id="ember1472" class="ember-view"><div id="ember4692" class="ember-view recent_ticket">
        <button id="ember4703" class="ember-view recent_ticket" type="button">
          <div class="ticket_status open">#1559681</div>
          <div class="info">
            Phone support
            <div class="requester_name"><script id="metamorph-485-start" type="text/x-placeholder"></script>Removed<script id="metamorph-485-end" type="text/x-placeholder"></script></div>
          </div>
        </button>
      </div><div id="ember4693" class="ember-view recent_ticket">
        <button id="ember4704" class="ember-view recent_ticket" type="button">
          <div class="ticket_status open">#1559655</div>
          <div class="info">
            Phone support
            <div class="requester_name"><script id="metamorph-486-start" type="text/x-placeholder"></script>Removed<script id="metamorph-486-end" type="text/x-placeholder"></script></div>
          </div>
        </button>
      </div><div id="ember4694" class="ember-view recent_ticket">
        <button id="ember4705" class="ember-view recent_ticket" type="button">
          <div class="ticket_status solved">#1551363</div>
          <div class="info">
            Phone support
            <div class="requester_name"><script id="metamorph-487-start" type="text/x-placeholder"></script>removed<script id="metamorph-487-end" type="text/x-placeholder"></script></div>
          </div>
        </button>
      </div><div id="ember4695" class="ember-view recent_ticket">
        <button id="ember4706" class="ember-view recent_ticket" type="button">
          <div class="ticket_status open">#1559638</div>
          <div class="info">
            Phone support
            <div class="requester_name"><script id="metamorph-488-start" type="text/x-placeholder"></script>Removed<script id="metamorph-488-end" type="text/x-placeholder"></script></div>
          </div>
        </button>
      </div><div id="ember4696" class="ember-view recent_ticket">
        <button id="ember4707" class="ember-view recent_ticket" type="button">
          <div class="ticket_status solved">#1559577</div>
          <div class="info">
            Phone support
            <div class="requester_name"><script id="metamorph-489-start" type="text/x-placeholder"></script>Removed<script id="metamorph-489-end" type="text/x-placeholder"></script></div>
          </div>
        </button>
      </div></div>
Link to comment
Share on other sites

  • Solution

Create functions, that wrap the current _ff functions.  Then you can loop, continually, for some given timeout (make that a parameter to the wrapping function) until the timeout is reached, or you grab the object, and return it.

Func WaitFor_FFXPath($sXpath, $sTimeoutMilliSec=10000)
    Local $iTimer = TimerInit(), $aReturn = ""
    While TimerDiff($iTimer)<$sTimeoutMilliSec
        $aReturn = _FFXPath($sXpath)
        If IsArray($aReturn) Then
            Return $aReturn
        EndIf
        Sleep (500)
    WEnd
    Return False
EndFunc
Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

 

Create functions, that wrap the current _ff functions.  Then you can loop, continually, for some given timeout (make that a parameter to the wrapping function) until the timeout is reached, or you grab the object, and return it.

 

Thank you. This makes a lot of sense.

On a related note, another problem I'm having is finding a way to accomplish the same thing but for fields that return null (that I will eventually write to). I'm new to AutoIt and am struggling with the idea that there doesn't appear to be a Null. Am I missing something or is "" always a string?

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