Jump to content

Automate - IE Selection on Page Load


 Share

Recommended Posts

I am new to AutoIT and struggling with a simple script. What I need help with is as follows: Open IE --> Particular URL --> Select Item --> Click on Go button.

Simple enough but the selection box (See DSPageLoad.jpg - Google Inspector) doesn't seem to a form or part of a form, and most of the tutorials focus around automated form inputs. 

1. Google Inspect - show the "selection box" as follows:

<select id="ddlplantNo" data-val="true" data-val-number="The field signageNo must be a number." data-val-required="The signageNo field is required." name="signageNo"><option value="1">Test1</option>
<option value="2">Test 2</option>
<option value="3">Test 3</option>
</select>

2. Google Inspect - shows the GO button as follows: 

<span class="ui-button-text">GO</span>

The script I have so far and it working is as follows:

SCRIPT:

#include <IE.au3>

Global $oIE = _IECreate ("http://signage.maritimepaper.com/signageappcorr")

 

 

 

DSPageLoad.jpg

Link to comment
Share on other sites

Thanks Danp2 for your help above. 

The following is working great for me but I am struggling to script the the last piece and that is clicking on the GO button, see my script below.

SCRIPT:

#include <IE.au3>

Call ("selection")

Func selection ()

Global $oIE = _IECreate ("http://signage.maritimepaper.com/signageappcorr")

Local $selectid = _IEGetObjByName ($oIE, "signageNo")

_IEFormElementOptionSelect ($selectid, "3")

EndFunc

 

 

Link to comment
Share on other sites

I am trying the following script and its not working, see error 

--> IE.au3 T3.0-2 Warning from function _IEGetObjByName, $_IESTATUS_NoMatch (Name: GO, Index: 0)
--> IE.au3 T3.0-2 Error from function _IEAction(click), $_IESTATUS_InvalidDataType

SCRIPT:

#include <IE.au3>

Call ("selection")

Func selection ()

Global $oIE = _IECreate ("http://signage.maritimepaper.com/signageappcorr")

Local $selectid = _IEGetObjByName ($oIE, "signageNo")
Local $button = _IEGetObjByName ($oIE, "GO")


_IEFormElementOptionSelect ($selectid, "3")
_IEAction ($button,"click")

EndFunc

 

 

Link to comment
Share on other sites

The button has no name, you will need to use _IETagNameGetCollection and loop thru the object until you find the one having innerText = "GO".

Next time you post code, please use this tool.

ps. do not use call unless it is necessary, just use Selection () directly

Link to comment
Share on other sites

The span element doesn't have a name or id attribute, so you can't use _IEGetObjByName or _IEGetObjById. A few options --

  • Look to see if this span is actually inside a link (<a> element). If so, you can likely use _IELinkClickByText
  • If not, then you can use _IETagNameGetCollection to get a collection of span elements and then loop through the collection to find the desired one. This has been demonstrated numerous times on the forum, so you should be able to find an example using the forum search feature
  • Lastly, you may be able to find a nearby element with either an ID or name. If so, you can possibly use it to locate the desired span element

A couple of additional pointers --

  • You don't need to use Call. Just execute the function like this --
    #include <IE.au3>
    
    selection()

     

  • Notice how I posted the code above? You can do the same by using the code button (looks like <>) in the toolbar.
Link to comment
Share on other sites

#include <IE.au3>
selection()

Func selection ()

Global $oIE = _IECreate ("http://signage.maritimepaper.com/signageappcorr")

Local $selectid = _IEGetObjByName ($oIE, "signageNo")

_IEFormElementOptionSelect ($selectid, "3")

EndFunc

clickobjbyclass($oIE, 'ui-button-text-only')

Func clickobjbyclass(ByRef $oIE, $class)
    $tags = $oIE.document.GetElementsByTagName('button')
    For $tag In $tags
        $class = $tag.GetAttribute('class')
        If String($class) = $class Then
            Return _IEAction($tag, 'click')
        EndIf
    Next
    Return False
EndFunc

Firstly Thanks for all the help, I think we are almost there.

The above scripts works fine until it runs the button piece. When the button script runs I am left with a browser with no info, it just blank.

see element inspectector for the button called "GO":

<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false" type="button">

<span class="ui-button-text">GO</span></button>

Note that I tried _IELinkClickByText and that didn't work for me.

 

 

 

 

 

 

 

Link to comment
Share on other sites

First you are reusing the $class as a parameter AND as a variable to capture the class attribute.  There should be 2 separate variables.

Second do not mix your main code in between functions.  It will get infernal to debug after awhile when the program gets bigger.  Put all your main code at the beginning of the script. 

Link to comment
Share on other sites

Pretty sure he means like this --

#include <IE.au3>
selection()
clickobjbyclass($oIE, 'ui-button-text-only') ; *********** Moved from below

Func selection ()
   Global $oIE = _IECreate ("http://signage.maritimepaper.com/signageappcorr")
   Local $selectid = _IEGetObjByName ($oIE, "signageNo")
   _IEFormElementOptionSelect ($selectid, "3")
EndFunc

Func clickobjbyclass(ByRef $oIE, $desiredclass) ; *********** Renamed parameter to prevent clash
    $tags = $oIE.document.GetElementsByTagName('button')
    For $tag In $tags
        $class = $tag.GetAttribute('class')
        If String($class) = $desiredclass Then
            Return _IEAction($tag, 'click')
        EndIf
    Next
    Return False
EndFunc

 

Link to comment
Share on other sites

Thanks Danp2 for the explanation, the code looks much neater and easier to understand.  I tried the above code and its still not working. Could you run the following code for me and let me know what I am missing.  URL is open to the public so it should resolve for you.

#include <IE.au3>
selection()
clickobjbyclass($oIE, 'ui-button-text-only') ; *********** Moved from below
clickobjbyclass2($oIE, 'ui-button-text-only')

Func selection ()
   Global $oIE = _IECreate ("http://signage.maritimepaper.com:8042/signageappcorr")
   Local $selectid = _IEGetObjByName ($oIE, "signageNo")
   _IEFormElementOptionSelect ($selectid, "3")
EndFunc

Func clickobjbyclass(ByRef $oIE, $desiredclass) ; *********** Renamed parameter to prevent clash
    $tags = $oIE.document.GetElementsByTagName('button')
    For $tag In $tags
        $class = $tag.GetAttribute('class')
        If String($class) = $desiredclass Then
            Return _IEAction($tag, 'click')
        EndIf
    Next
    Return False
 EndFunc

 

Link to comment
Share on other sites

Try this :

#include <Constants.au3>
#include <IE.au3>

Global $oIE

selection()
clickobjbyText($oIE, 'GO')

Func selection ()
   $oIE = _IECreate ("http://signage.maritimepaper.com:8042/signageappcorr")
   Local $selectid = _IEGetObjByName ($oIE, "signageNo")
   _IEFormElementOptionSelect ($selectid, "3")
EndFunc

Func clickobjbyText(ByRef $oIE, $desiredText)
    Local $tags = $oIE.document.GetElementsByTagName('span')
    For $tag In $tags
        If $tag.innerText = $desiredText Then
            ConsoleWrite ("found" & @CRLF)
            Return _IEAction($tag, 'click')
        EndIf
    Next
    Return False
EndFunc

 

Edited by Nine
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...