Jump to content
Sign in to follow this  
oemript

How to retrieve the class name using AutoIT?

Recommended Posts

Referring to following image, I would like to know on how to retrieve the class name under id="star_span" into variable

Star.png

 

Does anyone have any suggestions?
Thanks in advance for any suggestions

 

Share this post


Link to post
Share on other sites

How is this different from the post in your previous thread ?
What have you tried?

In other words: You really should know better by now than post questions without any effort to show for..... right?

Jos


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Referring to following coding, I would like to search for id="star_span" and return classname = "r_star0"

Do you have any suggestions?

Thank you very much for any suggestions (^v^)

6886f.png

 

#include <IE.au3>

   While ProcessExists("iexplore.exe")
       ProcessClose("iexplore.exe")
   WEnd

   ; 6886
   Global $oIE = _IECreate("https://financials.morningstar.com/ratios/r.html?t=0P0001648D&culture=en&platform=sal")

   Local $hIE = WinGetHandle("[Class:IEFrame]")
   Local $sSearch = "NIL"
   Local $oDivs = _IETagNameGetCollection($oIE, "star_span")
   WinActivate($hIE)
   For $oDiv In $oDivs
         If StringInStr($oDiv.ClassName, "r_star0") Then $sSearch &= 0
         If StringInStr($oDiv.ClassName, "r_star1") Then $sSearch &= 1
         If StringInStr($oDiv.ClassName, "r_star2") Then $sSearch &= 2
         If StringInStr($oDiv.ClassName, "r_star3") Then $sSearch &= 3
         If StringInStr($oDiv.ClassName, "r_star4") Then $sSearch &= 4
         If StringInStr($oDiv.ClassName, "r_star5") Then $sSearch &= 5
   Next

   MsgBox(32, "Search Items", $sSearch )

 

Edited by oemript

Share this post


Link to post
Share on other sites

Why are you searching for a colllection when you only want to get the Classname of a specific ID?
Isn't this what you want:

Global $oIE = _IECreate("https://financials.morningstar.com/ratios/r.html?t=0P0001648D&culture=en&platform=sal")
Local $oID = _IEGetObjById($oIE, "star_span")
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $oID.ClassName = ' & $oID.ClassName & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Referring to following image, I have already added 5 seconds to wait and still get error (showing error for sixth / seventh items within loop) would like to know on what wrong it is and how to handle it property.  Web page is loaded successfully,

Error.png

Do you have any suggestions?
Thank you very much for any suggestions (^v^)

 

Global $oIE = _IECreate("https://financials.morningstar.com/ratios/r.html?t=0P00009ROZ&culture=en&platform=sal")
      _IELoadWait($oIE, 5000)
      Local $sSearch = ""
      Local $oID = _IEGetObjById($oIE, "star_span")

 

Edited by oemript

Share this post


Link to post
Share on other sites
39 minutes ago, oemript said:

Do you have any suggestions?

Yes: Type the correct url and do some proper error checking.

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

I would like to know on why _IEQuit($oIE) cannot be executed in case of error and still display error as shown below:

"C:\Program Files (x86)\AutoIt3\Include\IE.au3" (1900) : ==> The requested action with this object has failed.:
If IsObj($oObject.document.getElementById($sID)) Then
If IsObj($oObject.document^ ERROR

After adding Global COM Error, I would like to know on what 1900 is about.

Error2.png

Do you have any suggestions?
Thank you very much for any suggestions (^v^)

 

#include <IE.au3>
Global $oGlobalCOMErrorHandler = ObjEvent("AutoIt.Error", "_ErrFuncGlobal") ; Global COM error handler
   While ProcessExists("iexplore.exe")
       ProcessClose("iexplore.exe")
   WEnd
      ; 6886
   Global $oIE = _IECreate("https://financials.morningstar.com/ratios/r.html?t=0P0001648D&culture=en&platform=sal")

   Local $hIE = WinGetHandle("[Class:IEFrame]")
   Local $sSearch = "NIL"
   Local $oID = _IEGetObjById($oIE, "star_span")
   if @error then
    ContinueLoop
     _IEQuit($oIE)
   else
     WinActivate($hIE)
     If StringInStr($oID.ClassName, "r_star0") Then $sSearch &= 0
     If StringInStr($oID.ClassName, "r_star1") Then $sSearch &= 1
     If StringInStr($oID.ClassName, "r_star2") Then $sSearch &= 2
     If StringInStr($oID.ClassName, "r_star3") Then $sSearch &= 3
     If StringInStr($oID.ClassName, "r_star4") Then $sSearch &= 4
     If StringInStr($oID.ClassName, "r_star5") Then $sSearch &= 5

     MsgBox(32, "Search Items", $sSearch )
   endif
   
   ; Global COM error handler
Func _ErrFuncGlobal($oError)
    ; Do anything here.
    ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> Global COM error handler - COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc

 

Edited by oemript

Share this post


Link to post
Share on other sites

@oemript

1. Why there is a ContinueLoop where there's no loop?

2. If you read carefully on the left of 1900, you'll see "err.scriptline: ", so, 1900 is the line where the error occurred;

3. You should look for the Error Code which is 80020008, which means "Bad variable type";

4. Why do you use Win* functions to get the handle of IE instead of using _IEPropertyGet($objIE, "hwnd");

5. &= Is a concatenation operator with strings, and you are using with integers.

Please, pay more attention on what you are doing, since, as @JLogan3o13 stated in one of your last threads, people are tired to see people only asking for code instead of putting a minimum effort to solve their "issues" :)


Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
8 hours ago, oemript said:

I would like to know on why _IEQuit($oIE) cannot be executed in case of error and still display error as shown below:

I gave you the answer so READ and THINK and CHECK!: 

13 hours ago, Jos said:

Yes: Type the correct url and do some proper error checking.

 


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Referring to following image, Error occur before 3, but it never goes to 4 and stop. I would like to know on how to manage error handle in case of any error, so it would jump to error section to perform _IEQuit($oIE).

Error4.png

Does anyone have any suggestions?
Thanks in advance for any suggestions

 

Local $sURL = "https://financials.morningstar.com/ratios/r.html?t=0P00009ROZ&culture=en&platform=sal"
Do
   While ProcessExists("iexplore.exe")
       ProcessClose("iexplore.exe")
   WEnd
   ; 1
   ConsoleWrite ( "1" )
   Global $oIE = _IECreate($sURL)
   ConsoleWrite ( "2" )
   _IELoadWait($oIE, 5000)
   ConsoleWrite ( "3" )
   Local $oID = _IEGetObjById($oIE, "star_span")
   ConsoleWrite ( "4" )
   If @error Then
      ConsoleWrite ( "5" )
      ContinueLoop
      ConsoleWrite ( "6" )
      MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.")
      ConsoleWrite ( "7" )
      _IEQuit($oIE)
      ConsoleWrite ( "8" )
   EndIf
   $i = $i + 1 
Until $i > 50

 

Edited by oemript

Share this post


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

Does anyone have any suggestions?

Yes...  but you still haven't fixed the issue from the previous thread in that code, so why did you start a new thread? 
Consider this your final warning as the next time you ask the same question without showing ANY new effort, you will get a vacation from our forums!

So: Start learning some basics and do the work YOURSELF !

Jos

 


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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...