Sign in to follow this  
Followers 0
Sienimies

Click on a website button that doesn't have a name or an id

4 posts in this topic

Hi,

I have tried hard to find the anwser, but haven't found anything that works.

I want to click on the button "Hae", but I can't use form submit, since this isn't the submit button in that form. And the button doesn't have a name or an id.

I can get to the editboxes just fine.

Website source:

<div>
    <label for="">Piiriväli</label>
    <input type="text" name="routeNumberFrom" value="" class="route" />
    <input type="text" name="routeNumberTo" value="" class="route" />
    <input type="button" class="button" value="Hae" onclick="submitAction('addRouteInterval');"/>
</div>

Code I have so far:

#include <IE.au3>

Opt("SendCapslockMode", 0) ;1=store and restore, 0=don't
Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

if MsgBox ( 1, "Jatketaanko", "Ennen kuin jatkat, avaa selain DI sivustolle, tulosta e-jakokirja kohtaan. Tyhjennä mahdolliset piiritiedot. Paina tämän jälkeen OK") = 1 Then

Local $hWin = WinGetHandle("Ejakokirjan tulostus", "") ; DI window

If IsHWnd($hWin) Then

  Local $o_IE = _IEAttach("Ejakokirjan tulostus")

        ConsoleWrite("Ejakokirjan tulostus window handle: $hWin = " & $hWin & @LF)

        ControlFocus($hWin, "", $hWin)

  Local $o_PiiriForm = _IEFormGetObjByName ($o_IE, "printableEbookForm") ; Form name

  Local $o_PiiriFrom = _IEFormElementGetObjByName ($o_PiiriForm, "routeNumberFrom") ; Editbox name

  _IEFormElementSetValue ($o_PiiriFrom, "1022001")

  Local $o_PiiriTo = _IEFormElementGetObjByName ($o_PiiriForm, "routeNumberTo") ; Editbox name

  _IEFormElementSetValue ($o_PiiriTo, "1022009")

  ; Click HAE

  Else
        ConsoleWrite("Debug: Error, failed to get control handle for Ejakokirjan tulostus window." & @LF)
  EndIf
EndIf

Share this post


Link to post
Share on other sites



If you gave us a link to the exact page, that would help us to help you.


#include <ByteMe.au3>

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

HI,

It looks like you could just call the Javascript function 'submitAction' directly.

$o_IE.document.parentWindow.ExecScript("submitAction('addRouteInterval');")

or you can loop over all input elements and match the value.

Local $oInput, $oInputs = _IETagNameGetCollection($o_IE, 'input', -1)
For $oInput In $oInputs
    If $oInput.value == 'Hae' Then
        _IEAction($oInput, "click")
        _IELoadWait($o_IE)
    EndIf
Next
Edited by Robjong

Share this post


Link to post
Share on other sites

Hi,

Sorry for the late answer, have been busy :oops:

@Sleepydvdr, I can't provide a direct link since the site is behind password protection.

@Robjong, fantastic ! The direct call to the javascript was exactly what I have been looking for. Didn't stumble upon that one anywhere.

Thank you for your help.

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
Sign in to follow this  
Followers 0