Jump to content

Trying to automate list sorting


Recommended Posts

Hello everyone,

I'm trying to build a bot that automates downloading files, but for that I must sort the file list first.

$a = _IETagNameGetCollection($tag, "a")
    ConsoleWrite($a & " ")
    For $link in $a
        $classField = $link.GetAttribute("class")
        ConsoleWrite("_" &$classField & "_  ")
        If $classField = "k-link" Then
        ConsoleWrite($link.document.GetElementsByTagName("span"))
            If $link.document.GetElementsByTagName("span") then
                $spTag = _IETagNameGetCollection($link, "span")
                ConsoleWrite("_" & $spTag & "_  ")
                For $span in $spTag
                    $class = $span.GetAttribute("class")
                    ConsoleWrite("_" & $class & "_  ")
                    If $class = "k-icon k-i-arrow-s" Then
                        _IEAction($tag, "click")
                        Sleep(1500)
                        _IEAction($tag, "click")
                        Sleep(1500)
                        ExitLoop
                    ElseIf $class = "k-icon k-i-arrow-n" Then
                        Sleep(1500)
                        ExitLoop
                    EndIf
                Next
            Else
                _IEAction($tag, "click")
                Sleep(1500)
                ExitLoop
            EndIf
            ExitLoop


            EndIf
    Next

I build this trying to check the value of the order button and give it the necessary number of presses to order it the right way.

this is the HTML tag of the button in unsorted state:

<a class="k-link" href="/Monitor/PopulaGrid?gridMonitor-sort=NumeroDocumento-asc">Num Doc</a>

When it's ordered (ascending or descending) it's like this:

<a class="k-link" href="/Monitor/PopulaGrid?gridMonitor-sort=NumeroDocumento-asc">Num Doc<span class="k-icon k-i-arrow-(x)"></span></a>

as you can see when it's sorted a new span tag appears inside the original one that let's you get the order it's sorted.

My first thought to solve this is trying to see if this tag exists (if it doesn't i could take proper action, if it does i could check it's value and also act accordingly) but i don't to see to know how to check this.

Can someone help me to solve how to do this.

Link to comment
Share on other sites

That seems to work fine in my test environment :

_IELoadWait($oIE)
  Local $oTags = _IETagNameGetCollection($oIE, "a")
  Local $sClass, $oLinks, $oSpan
  For $oTag in $oTags
    $sClass = $oTag.GetAttribute("class")
    ConsoleWrite("_" & $sClass & "_" & @CRLF)
    If $sClass = "k-link" Then
      $oSpan = $oTag.firstElementChild
      If IsObj($oSpan) Then
        ConsoleWrite ("Child Found" & @CRLF)
      Else
        ConsoleWrite ("Child not found" & @CRLF)
      EndIf
    EndIf
  Next

 

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