oemript Posted March 20, 2020 Share Posted March 20, 2020 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 Link to comment Share on other sites More sharing options...
Danp2 Posted March 20, 2020 Share Posted March 20, 2020 Yes... it should be possible to click that element using Autoit. The solution will depend on the browser being used. Hint: You most likely need to click the button element instead of the span element. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Nine Posted March 20, 2020 Share Posted March 20, 2020 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... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
oemript Posted March 20, 2020 Author Share Posted March 20, 2020 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) Link to comment Share on other sites More sharing options...
Nine Posted March 20, 2020 Share Posted March 20, 2020 (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 March 20, 2020 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Danp2 Posted March 20, 2020 Share Posted March 20, 2020 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 oemript 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
oemript Posted March 20, 2020 Author Share Posted March 20, 2020 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 Link to comment Share on other sites More sharing options...
Danp2 Posted March 20, 2020 Share Posted March 20, 2020 @SonyStyle Did you try running the code exactly as I posted above? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Nine Posted March 20, 2020 Share Posted March 20, 2020 (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 : expandcollapse popup#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 March 20, 2020 by Nine oemript 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
oemript Posted March 21, 2020 Author Share Posted March 21, 2020 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 expandcollapse popupLocal $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 Link to comment Share on other sites More sharing options...
oemript Posted March 21, 2020 Author Share Posted March 21, 2020 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 Link to comment Share on other sites More sharing options...
Nine Posted March 21, 2020 Share Posted March 21, 2020 There 2 spaces after Balance Sheet. You have only one. Tested and working... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Danp2 Posted March 21, 2020 Share Posted March 21, 2020 7 hours ago, SonyStyle said: Yes, but the code is missing Step 1 before Step 2 Sorry, but that doesn't compute with me. Want to try again to explain why the code I posted didn't work for you? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
oemript Posted March 21, 2020 Author Share Posted March 21, 2020 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 Link to comment Share on other sites More sharing options...
bdr529 Posted March 26, 2020 Share Posted March 26, 2020 (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 expandcollapse popup#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 March 26, 2020 by bdr529 To community goes all my regards and thanks Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now