Jump to content

Recommended Posts

Posted (edited)

I don't know if this is possible or not in auto it.. I have been searching for this for days now. so here it is; I am trying to loop through each class in a div tag on a website and perform some set of actions. I am able to only go through the first class.  For example I am able to click on the profile card-bg js-nav of the first class in grid Grid -with gutter .. But the other classes in it with the same name as Grid cell ....  I am unable to reach them .. 

Also to make it more clear I am looking something similar to ".each" in JQuery .. 

Any Help would be really appreciated ..!! 

Thank you.

This is the code I've written to access the loop .

Func Search()
    _IENavigate($oIE, "https://........")
    Local $divs = _IETagNameGetCollection($oIE, "div")
    For $div In $divs
        If $div.className == "Grid Grid--withGutter" Then
            $oFound = ""
            $colLinks = _IELinkGetCollection($oIE)
            For $oLink In $colLinks
                If $oLink.className & "" = "ProfileCard-bg js-nav" Then
                    $oFound = $oLink
                    _IEAction($oFound, "click")
                    ExitLoop
                EndIf
            Next
        EndIf
    Next

EndFunc

 

Below attached is the js of the page.  

Untitled.png

Edited by DoomSack
Making my problem to understand better.
Posted

@DoomSack please read  How to post code on the forum 

Here is example how you can try to solve your problem:

#include <IE.au3>

_Example()
Func _Example()
    Local $oIE = _IEAttach(.....)
    Local $oIE_DIV = _IEGetObjById($oIE,'stream-item-user-3099023815')
    
    ; first approach
    Local $oIE_ObjectToClick1 = $oIE_DIV.nextElementSibling.nextElementSibling
    _IEAction($oIE_ObjectToClick1,'click')

    ; second approach
    Local $oIE_ObjectToClick2 = $oIE_DIV.nextSibling.nextSibling
    _IEAction($oIE_ObjectToClick2,'click')
EndFunc

 

Some reference documentation:
https://msdn.microsoft.com/en-us/library/ms535240(v=vs.85).aspx

https://msdn.microsoft.com/en-us/library/ff974796(v=vs.85).aspx
https://msdn.microsoft.com/en-us/library/ms534189(v=vs.85).aspx

 

 

btw.
Welcome to the forum.

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

@mLipok

Firstly, I have edited the question and posted it according to the forum rules.

Secondly, Thank you very much,  really appreciate the reply, I am going to try out the code and reply here again.

Lastly, Thank you , I am pleased to be a part of Autoit.

Posted (edited)

@mLipok

I have tried that, but there is a problem with it. Everything is working as it is supposed to only for two rounds and then it exits saying error.

#include <IE.au3>
#include <AutoItConstants.au3>


Local $oIE = _IECreate("https://.....")
$HWND = _IEPropertyGet($oIE, "hwnd")
WinSetState($HWND, "", @SW_MAXIMIZE)

Local $oIE_DIV = _IETagNameGetCollection($oIE, "div")

For $oIE_DIV1 In $oIE_DIV
    If $oIE_DIV1.className == "GridTimeline-items" Then
        Local $oIE_ObjectToClick2 = $oIE_DIV1.firstElementChild ;grid gutter
        Local $oCount = $oIE_ObjectToClick2.childElementCount
        Local $oChild = $oIE_ObjectToClick2.lastElementChild ;grid cells
        ;MsgBox(0, "", $oCount)
        While ($oCount)
            traverse()
            $oChild = $oChild.previousElementSibling
        WEnd
    EndIf
Next

Func traverse()
    Local $obabys = _IETagNameGetCollection($oChild, "a")
    For $obaby In $obabys
        If $obaby.className = "ProfileCard-bg js-nav" Then
            _IEAction($obaby, "click")
            Sleep(3000)
            _IEAction($oIE, "back")
            Sleep(4000)
            Send("{DOWN}")
            Send("{DOWN}")
            ExitLoop
        EndIf
    Next
EndFunc   ;==>traverse
>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Users\rbauser1\Documents\Twitter v2.au3" /UserParams    
+>14:26:50 Starting AutoIt3Wrapper v.15.920.938.0 SciTE v.3.6.0.0   Keyboard:00004009  OS:WIN_10/  CPU:X64 OS:X64    Environment(Language:0409)
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\rbauser1\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\rbauser1\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.2)  from:C:\Program Files (x86)\AutoIt3  input:C:\Users\rbauser1\Documents\Twitter v2.au3
+>14:26:50 AU3Check ended.rc:0
>Running:(3.3.14.2):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\rbauser1\Documents\Twitter v2.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
"C:\Users\rbauser1\Documents\Twitter v2.au3" (22) : ==> The requested action with this object has failed.:
$oChild = $oChild.previousElementSibling
$oChild = $oChild^ ERROR
->14:27:13 AutoIt3.exe ended.rc:1
+>14:27:13 AutoIt3Wrapper Finished.
>Exit code: 1    Time: 23.34

This is the error it shows after performing correctly for two times. I don't know where I am going wrong .

Edited by DoomSack
Posted (edited)

In post #2 I show you only an conceptual example.
If you want to use it you should use it properly.

So please read: How to use IE.au3  UDF with  AutoIt v3.3.14.x  

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Why you are using send in IE automation script ??

            Sleep(4000)
            Send("{DOWN}")
            Send("{DOWN}")

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 2/25/2016 at 9:05 AM, mLipok said:

In post #2 I show you only an conceptual example.
If you want to use it you should use it properly.

 How to use IE.au3  UDF with  AutoIt v3.3.14.x  

Expand  

I am Probably doing it correctly, to my knowledge. I modified what you gave in the example which was really helpful in figuring out the real methods that i needed to use.. I Just need to know where I am going wrong.. I am pretty sure it is a minor mistake , any help would be greatly appreciated.

Posted (edited)
  On 2/25/2016 at 9:08 AM, mLipok said:

Why you are using send in IE automation script ??

            Sleep(4000)
            Send("{DOWN}")
            Send("{DOWN}")
Expand  

That is just for scrolling . I was just checking out things.

Edited by DoomSack
Posted

@mLipok

I followed the udf as you suggested and this is the error that appears.

>Running:(3.3.14.2):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\rbauser1\Desktop\AutoIt Scripts\Twitter v2.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
--> COM Error encountered in Twitter v2.au3 (23) :
----> $IEComErrorNumber         = 0x80070005 (-2147024891)
----> $IEComErrorWinDescription = Access is denied.
----> $IEComErrorDescription    = 
----> $IEComErrorSource         = 
----> $IEComErrorHelpFile       = 
----> $IEComErrorHelpContext    = 
----> $IEComErrorLastDllError   = 0
----> $IEComErrorRetcode        = 0x00000000
--> IE.au3 T3.0-2 Error from function _IETagNameGetCollection, $_IESTATUS_InvalidDataType
--> COM Error encountered in Twitter v2.au3 (30) :

 

Posted
  On 2/25/2016 at 11:04 AM, DoomSack said:

----> $IEComErrorWinDescription = Access is denied.

Expand  

This is all what you need to know. 
IE do not allow you to do what you want.

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

@mLipok

I found the problem it was with _Ieaction tag which I was using. So I changed my approach and used the following code.. Now All I need is the same above error comes when I put the loop under the parent div tag . How can I overcome it ? Please help.

IEErrorHandlerRegister(_User_ErrFunc)

Local $oIE = _IECreate("https://.....")
$HWND = _IEPropertyGet($oIE, "hwnd")
WinSetState($HWND, "", @SW_MAXIMIZE)

Local $oIE_DIV = _IETagNameGetCollection($oIE, "div")


For $oIE_DIV1 In $oIE_DIV
    If $oIE_DIV1.className == "GridTimeline-items" Then
        Local $oCount1 = $oIE_DIV1.childElementCount
        Local $oIE_ObjectToClick2 = $oIE_DIV1.firstElementChild ;grid gutter

        While ($oCount1)
                InChild()
            $oIE_ObjectToClick2 = $oIE_ObjectToClick2.nextElementSibling
        WEnd
    EndIf
Next

Func InChild()
    Local $oCount = $oIE_ObjectToClick2.childElementCount
    Local $oChild = $oIE_ObjectToClick2.firstElementChild
    While ($oCount)
        Local $obabys = _IETagNameGetCollection($oChild, "a")
    For $obaby In $obabys
        If $obaby.className = "ProfileCard-bg js-nav" Then

            Local $olink = $obaby.href

            Local $oIE1 = _IECreate($olink)
            _IELoadWait_ForAllFrames($oIE)
            Sleep(1000)
            _IEQuit($oIE1)
            Sleep(1000)
            WinActivate("....")
            Send("{DOWN}")
            ExitLoop
        EndIf
    Next
        $oChild = $oChild.nextElementSibling
    WEnd

EndFunc   ;==>InChild

 

Posted

@mLipok

Thank you very much .. I just needed the boost .. I am done with the script and it is running completely fine.. The problem was I was not exiting the child loop.. !!!!

:):):)

Posted

Good to hear that.

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

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
×
×
  • Create New...