Jump to content
Sign in to follow this  
CaptainBeardsEyesBeard

clicking a Div button

Recommended Posts

Hi 

 

I'm trying to click a button and tried a few different ways

 

This is the HTML for the button 

<button class="btn btn-info dim" style="float: right;" onclick="performSearch()">Search</button>

So I tried this

 

$oSubmitClick = _IEGetObjByName($oIE,"btn btn-info dim")
_IEAction($oSubmitClick, "click")
_IELoadWait($oIE,2000)

But it doesn't work 

Share this post


Link to post
Share on other sites

@CaptainBeardsEyesBeard
That's because the property "name" doesn't exist in that element, as you can see.
You should get it through the property "ClassName"; there are plenty samples on the Forum.

P.S.: always add some error checking to your code, so you can see what is going on :) 


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites

If several buttons have got the same classname, you might try _IETagNameGetCollection (button), then loop through the collection looking for innertext == "Search"

Share this post


Link to post
Share on other sites
9 minutes ago, mikell said:

If several buttons have got the same classname, you might try _IETagNameGetCollection (button), then loop through the collection looking for innertext == "Search"

Hmm 

 

So i tried this too 😕 

 

Local $activeButtons= _IEGetObjById($oIE, "clientSearch")
Sleep(5000)

Local $oButtons = _IETagNameGetCollection($oIE, $activeButtons)
For $oButton In $oButtons
    ;~ Check if Button InnerText equals Log In and perform an action.
    ;~ Uncomment the _IEAction line below to submit the form.
    If $oButton.InnerText = "Search" Then
        MsgBox(64, 'Search Found', 'Button found with value: ' & $oButton.InnerText, 4)
        _IEAction($oButton, 'click')
        Sleep(6000)
        _IEFormElementSetValue($oButton, "AutoIt IE.au3")
        MsgBox($MB_SYSTEMMODAL, "Test Result    ", "Test passed: can't find search box " &  $oButton.InnerText & "", 4)
            FileWrite($TestLog, @CRLF & "Test" & $TestCount & " Test passed: Can't find search box" & $ObjID.innerText)
     Else
            MsgBox($MB_SYSTEMMODAL, "Test Result    ", "Test Failed: can't find search box " &  $oButton.InnerText & "", 4)
            FileWrite($TestLog, @CRLF & "Test" & $TestCount & " Test failed: Can't find search box" & $ObjID.innerText)


    EndIf
 Next

And the button I want is in this id

<div class="tab-pane active" id="clientSearch">
          
                        <td colspan="2">
                            <div class="text-right">
                                <button class="btn btn-info dim" style="float: right;" onclick="performSearch()">Search</button>

 

Share this post


Link to post
Share on other sites

If you put this after your tagnameGetCollection (buttons) :

MsgBox (0,"Debug",IsObj ($oButtons))

What does it say to you ?

Share this post


Link to post
Share on other sites

Hmmm, you are right.  But it shouldn't cause your tagname is an object while it should be a string...Well I suppose it is kind of a feature.  But if you test .lenght of the collection, you will see it is emply (0).

Share this post


Link to post
Share on other sites
On 8/22/2019 at 1:13 PM, Danp2 said:

If you want further assistance, you'll need to help us to help you. 😉

Post the results from the Scite output panel so that we can get a better idea of what's happening.

By scite output you just mean this right? 

 

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\EliteAutomationKnowYourClient\Framework\TestEnv.au3"    
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
>Exit code: 0    Time: 79.02

Any further assistance on this? 

 

To recap I'm using this code

Local $oElements = _IETagNameGetCollection($oIE, "btn btn-info")

For $oElement In $oElements

   if $oElement.classname=="AVI673" then

     _IEAction ($oElement, "click")

   EndIf
;ConsoleWrite ( $oElement.classname & @CRLF)
 next

To try to access this html 

 

1.png

Edited by CaptainBeardsEyesBeard

Share this post


Link to post
Share on other sites

Also I tried this and couldn't click either 😕

local $oButtons = _IETagNameGetCollection($oIE, "btn btn-info")

For $oButton In $oButtons
   ;~ Check if Button InnerText equals Log In and perform an action.
   ;~ Uncomment the _IEAction line below to submit the form.
   If $oButton.InnerText = "AVI673" Then
       MsgBox(64, 'AVI673 Found', 'Button found with value: ' & $oButton.InnerText, 4)
       _IEAction($oButton, 'click')
        Sleep(6000)
        _IEFormElementSetValue($oButton, "AutoIt IE.au3")
        MsgBox($MB_SYSTEMMODAL, "Test Result    ", "Test passed: can't find button box " &  $oButton.InnerText & "", 4)
            FileWrite($TestLog, @CRLF & "Test" & $TestCount & " Test passed: Can't find button box" & $ObjID.innerText)
     Else
            MsgBox($MB_SYSTEMMODAL, "Test Result    ", "Test Failed: can't find button box " &  $oButton.InnerText & "", 4)
            FileWrite($TestLog, @CRLF & "Test" & $TestCount & " Test failed: Can't find button box" & $ObjID.innerText)


   EndIf
Next

 

Share this post


Link to post
Share on other sites

"btn btn-info" is not a tag name, tags are "div", "tr" or "button", here is a basic working example of clicking a button tag.

#include <IE.au3>

Local $oIE = _IECreate("https://sweetalert2.github.io/", 1)
Local $oButtons = _IETagNameGetCollection($oIE, "button")
If @error Then MsgBox(4096, "", "Error - Unable getting button collection" & @CRLF & "Error : " & @error)
If IsObj($oButtons) Then
    For $oButton In $oButtons
        If StringInStr($oButton.innerText, "Show normal alert") Then
            MsgBox(4096, "", "Clicking Show normal message")
            _IEAction($oButton, "Click")
        EndIf
        If StringInStr($oButton.innerText, "Show success message") Then
            MsgBox(4096, "", "Clicking Show success message button")
            _IEAction($oButton, "Click")
        EndIf
    Next
EndIf

 

Share this post


Link to post
Share on other sites

So this would be correct? 

local $oButtons = _IETagNameGetCollection($oIE, "button")

For $oButton In $oButtons
   ;~ Check if Button InnerText equals Log In and perform an action.
   ;~ Uncomment the _IEAction line below to submit the form.
   If $oButton.InnerText = "AVI673" Then
       MsgBox(64, 'AVI673 Found', 'Button found with value: ' & $oButton.InnerText, 4)
       _IEAction($oButton, 'click')
        Sleep(6000)
        _IEFormElementSetValue($oButton, "AutoIt IE.au3")
        MsgBox($MB_SYSTEMMODAL, "Test Result    ", "Test passed: can't find button box " &  $oButton.InnerText & "", 4)
            FileWrite($TestLog, @CRLF & "Test" & $TestCount & " Test passed: Can't find button box" & $ObjID.innerText)
     Else
            MsgBox($MB_SYSTEMMODAL, "Test Result    ", "Test Failed: can't find button box " &  $oButton.InnerText & "", 4)
            FileWrite($TestLog, @CRLF & "Test" & $TestCount & " Test failed: Can't find button box" & $ObjID.innerText)


   EndIf
Next

 

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...