Jump to content
oemript

Can AutoIT click button on web?

Recommended Posts

Referring to following link and image, can AutoIT script click button on web?

 

 

Thanks for any suggestions

https://www.morningstar.com/stocks/xnas/goog/financials

Morn.png

Share this post


Link to post
Share on other sites

As Danp2 said, it shouldn't be problem.  I have been automating morningstar.ca a number of times with IE UDF and it has always been quite straightforward... 

Share this post


Link to post
Share on other sites

I get no idea on how to grab the object "Export to Excel" and click it and save the file.

 

 

I would like to know on how AutoIT handles this process.

Thanks for any help

#include <IE.au3>
#include <WinAPIFiles.au3>
#include <File.au3>
_IEErrorNotify(True)
Global $oGlobalCOMErrorHandler = ObjEvent("AutoIt.Error", "_ErrFuncGlobal") ; Global COM error handler
Global $Init_Time = TimerInit()
;AdlibEnable("Check_Running_Time")

Local $i = 0
Local $sSearch = ""
Local $sURL = FileReadLine("https://www.morningstar.com/stocks/xnas/goog/financials", 1)

      Global $oIE = _IECreate($sURL)
      _IELoadWait($oIE, 2000, 3000)
      _IENavigate($oIE, "javascript:SRT_stocFund.Export()")
            
      How to grab the object "Export to Excel" and click it and save the file?
      
      Sleep(5000)
      _IEQuit($oIE)

Goo.png

Share this post


Link to post
Share on other sites
Posted (edited)

Since I don't have access to the button (maybe you have a premium account ?), you could try this :

#include <IE.au3>

Local $sURL = "https://www.morningstar.com/stocks/xnas/goog/financials"
Local $oIE = _IECreate($sURL)
Local $cTags = _IETagNameGetCollection ($oIE, "button")
For $oTag in $cTags
  If $oTag.className = "sal-financials-details_export mds-button mds_button--small" Then
    $oTag.click ()
    ExitLoop
  EndIf
Next

Make sure I did copy the className right...

Edited by Nine

Share this post


Link to post
Share on other sites

This works for me to find / click the desired button --

#include <IE.au3>

Local $sURL = "https://www.morningstar.com/stocks/xnas/goog/financials"
Local $sText = " Income Statement  "

Local $oIE = _IECreate($sURL)
Sleep(5000)
_IELinkClickByText($oIE, $sText)
Sleep(5000)

$sText = " Export to Excel "
Local $oButtons = _IETagNameGetCollection ($oIE, "button")
For $oButton in $oButtons
  If $oButton.InnerText = $sText Then
    ConsoleWrite("Button found!" & @crlf)
    $oButton.click()
    ExitLoop
  EndIf
Next

 

Share this post


Link to post
Share on other sites

Referring to following images, should I use classname "mds-link ng-binding" as object to be clicked on the first step?

I try both coding and fail to clicking button "Income Statement", furthermore, when I right click the object "Income Statement" for inspect, but I cannot find classname "sal-financials-details_export mds-button mds_button--small" by searching, on the other hands, " Income Statement  " is not an object for selection, so clicking action on "Income Statement" cannot be performed,

Do you have any suggestions on what wrong it is?

Thanks for any help

 

 

 

 

Goo1.png

Share this post


Link to post
Share on other sites
Posted (edited)

I can confirm that Danp2 code is working fine, but there was an invalid character after copy/paste.  Maybe SonyStyle has the same problem.  To delete those bad characters, in Scite, go to menu File/Encoding and select Code Page Property.  You should now be able to see them, just simply delete them.  While we are here I added the code I use to save file, so here you go :

#include <IE.au3>

Local $sURL = "https://www.morningstar.com/stocks/xnas/goog/financials"
Local $sText = " Income Statement  "

Local $oIE = _IECreate($sURL)
Sleep(6000)
_IELinkClickByText($oIE, $sText)
Sleep(6000)

Local $sText = " Export to Excel ", $bFound = False
Local $oButtons = _IETagNameGetCollection($oIE, "button")
For $oButton In $oButtons
  If $oButton.InnerText = $sText Then
    $bFound = True
    $oButton.click()
    ExitLoop
  EndIf
Next

If Not $bFound Then Exit MsgBox($MB_SYSTEMMODAL, "", "Export button not found")
Sleep(5000)
Local $hIE = _IEPropertyGet($oIE, "hwnd")
Local $hCtrl = ControlGetHandle($hIE, "", "[CLASSNN:DirectUIHWND1]")
ControlSend($hIE, "", $hCtrl, "{TAB}")
Sleep(350)
ControlSend($hIE, "", $hCtrl, "{DOWN}") ; this does work once the save button is focussed
ControlSend($hIE, "", $hCtrl, "s")
Local $sFile = @ScriptDir & "\Test.xls"
FileDelete($sFile)
Local $hWnd = WinWait("[CLASS:#32770]", "", 5)
If Not $hWnd Then Exit MsgBox($MB_SYSTEMMODAL, "", "Timeout on Save As Window")
Sleep(1000)
ControlSetText($hWnd, "", "Edit1", $sFile)
ControlClick($hWnd, "", "[CLASSNN:Button1]")
For $i = 1 To 25
  ConsoleWrite(FileGetSize($sFile) & @CRLF)
  If FileGetSize($sFile) Then ExitLoop
  Sleep(200)
Next
_IEQuit($oIE)

 

Edited by Nine

Share this post


Link to post
Share on other sites

Please see attached image and codes

I am little confused on what object should be grabbed for locating clicking action.

Step 1 - Locating text " Income Statement " as object, Pass

Step 2 - Locating button " Export to Excel " as object, Pass

Step 3 - Locating label " Balance Sheet " as object, but Fail

Any suggestions on what object should be grabbed for "Balance Sheet "?

Thanks for any help

Local $sURL = "https://www.morningstar.com/stocks/xnas/goog/financials"

;Step 1 - Click Income Statement
Local $sText = " Income Statement  "
Local $oIE = _IECreate($sURL)
Sleep(6000)
_IELinkClickByText($oIE, $sText)
Sleep(6000)

Local $sText = " Export to Excel ", $bFound = False
Local $oButtons = _IETagNameGetCollection($oIE, "button")
For $oButton In $oButtons
  If $oButton.InnerText = $sText Then
    $bFound = True
    $oButton.click()
    ExitLoop
  EndIf
Next

When I grab the label Object Class and search for " Balance Sheet ", it fails, what object should be grab in order to switch into "Balance Sheet"?
Local $sText = " Balance Sheet ", $bFound = False
Local $oLabels = _IETagNameGetCollection($oIE, "label")
For $oLabel In $oLabels
  If $oLabel.InnerText = $sText Then
    $bFound = True
    $oLabel.click()
    ExitLoop
  EndIf
Next

Local $sText = " Export to Excel ", $bFound = False
Local $oButtons = _IETagNameGetCollection($oIE, "button")
For $oButton In $oButtons
  If $oButton.InnerText = $sText Then
    $bFound = True
    $oButton.click()
    ExitLoop
  EndIf
Next

Goo2.png

Share this post


Link to post
Share on other sites
12 hours ago, Danp2 said:

@SonyStyle Did you try running the code exactly as I posted above?

Yes, but the code is missing Step 1 before Step 2

Step 1 - Locating text " Income Statement " as object, Pass

Step 2 - Locating button " Export to Excel " as object, Pass

Thanks for any help

Share this post


Link to post
Share on other sites
1 hour ago, Danp2 said:

Sorry, but that doesn't compute with me. Want to try again to explain why the code I posted didn't work for you?

It works now after changing Sleep(10000), maybe the network traffic issue.

Thanks everyone for any help

Share this post


Link to post
Share on other sites
Posted (edited)
On 3/21/2020 at 4:13 PM, SonyStyle said:

It works now after changing Sleep(10000), maybe the network traffic issue.

Thanks everyone for any help

#include <IE.au3>
dim $spt=SplashTextOn("", "wait A", 300, 100)
local $hTimer_max=10000 ; 10 second
Local $sURL = "https://www.morningstar.com/stocks/xnas/goog/financials"
Local $sText = " Income Statement  "
local $hTimer
local $continue=true
Local $oIE = _IECreate($sURL)
while 1
    if $oIE.document.readyState="complete" and Not _IEPropertyGet($oIE, "busy") then exitloop
wend
ControlSetText($spt, '', 'Static1',"wait B")
$hTimer = TimerInit()
while 1
    if TimerDiff($hTimer)>$hTimer_max then
        $continue=false
        splashoff()
        msgbox(16,"error timeout",$sText)
    endif
    if stringinstr(_IEBodyReadText($oIE),$sText) then exitloop
wend
if $continue=true then  
    ControlSetText($spt, '', 'Static1',"wait C")
    _IELinkClickByText($oIE, $sText,"",0)
    while 1
        if $oIE.document.readyState="complete" and Not _IEPropertyGet($oIE, "busy") then exitloop
    wend
    ControlSetText($spt, '', 'Static1',"wait D")
    $sText = "Export to Excel"
    $hTimer = TimerInit()
    while 1
        if TimerDiff($hTimer)>$hTimer_max then
            $continue=false
            splashoff()
            msgbox(16,"error timeout",$sText)
        endif
        if stringinstr(_IEBodyReadText($oIE),$sText) then exitloop
    wend
    if $continue=true then
        local $bFound = False
        Local $oButtons = _IETagNameGetCollection($oIE, "button")
        For $oButton In $oButtons
          If stringinstr($oButton.InnerText,$sText) Then
            $bFound = True
            $oButton.click()
            ExitLoop
          EndIf
        Next
        if $bFound=false Then
            $continue=false
            splashoff()
            msgbox(16,"error",$sText)
        endif
        if $continue=true then
            ControlSetText($spt, '', 'Static1',"wait E")
            $hTimer = TimerInit()
            while 1
                if TimerDiff($hTimer)>$hTimer_max or ControlGetHandle("[title:Alphabet Inc Class C (GOOG) Financials | Morningstar - Internet Explorer]", "", "[CLASS:DirectUIHWND; INSTANCE:1]")<>0  then exitloop
            wend
            splashoff()
        endif
    endif
endif

 

Edited by bdr529

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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...