Iterate Chrome page variable buttons

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
drunkenmonkey
Pro Scripter
Posts: 90
Joined: Fri Jan 31, 2020 10:52 am

Iterate Chrome page variable buttons

Post by drunkenmonkey » Thu Nov 04, 2021 11:12 am

Hi! Hope you can help me with this problem!
In "Related content" page there is a variable "ressource-list" content.
In this exemple there is 4. For other webcast it could be 2 or 3 or none.
https://u.pcloud.link/publink/show?code ... aw7mS6Xhtk
When there is a list, for each ressource, a detail button is display. When
it is clicked a page report is displayed and the download of an excel file
is available.
https://u.pcloud.link/publink/show?code ... bfwmVGlu1y
I want to access to all excel files and download them.
How to find the xpath of each ressource button?
So from there I can automate the rest of the script and download each xl file?
HTML of the ressource report bloc.
https://u.pcloud.link/publink/show?code ... 6UCSeneHMk
Thank you so much for your help!

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1386
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Iterate Chrome page variable buttons

Post by Dorian (MJT support) » Thu Nov 04, 2021 12:41 pm

This should work :

Code: Select all

ChromeFindElements>session_id,xpath,//span[@class='btn-link'],el

if>el_count>0
  //click loop
  let>clickloop=0
  repeat>clickloop
    let>clickloop=clickloop+1
    let>element=el_%clickloop%
    ChromeElementAction>session_id,element,click
  Until>clickloop,el_count
  else>elements not found
endif
Yes, we have a Custom Scripting Service. Message me or go here

drunkenmonkey
Pro Scripter
Posts: 90
Joined: Fri Jan 31, 2020 10:52 am

Re: Iterate Chrome page variable buttons

Post by drunkenmonkey » Fri Nov 05, 2021 6:37 pm

Thank you Dorian for your help!

Unfortunately this code does not work.
Regardless of the strategy used, XPath, Class Name nothing does.

Thank you again!

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1386
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Iterate Chrome page variable buttons

Post by Dorian (MJT support) » Fri Nov 05, 2021 7:00 pm

Then investigate to see if it's in a frame. I tested my code and it found the elements without issue.
Yes, we have a Custom Scripting Service. Message me or go here

drunkenmonkey
Pro Scripter
Posts: 90
Joined: Fri Jan 31, 2020 10:52 am

Re: Iterate Chrome page variable buttons

Post by drunkenmonkey » Sun Nov 07, 2021 1:11 pm

Thank you for your answer.
I guess you are right, there is frames. In the page code it is ref to container.
As new in this, I will try to master one thing first and it is to select a menu item called Interactions in left menu
of this page. I will try after to go on with other task like ckicking those detail buttons.

Here's the screen capture.
https://u.pcloud.link/publink/show?code ... VnDHzdLB2k

And here's the piece of code. But when I run it res=0 but the nothing happen after.

Code: Select all

//Find the frame
ChromeFindElements>session_id,xpath,//SCRIPT[@src='_SupportFiles/common.js'],elements
//switch to the first frame
ChromeSwitchFrame>session_id,element,elements_3,res
//now anything we do is inside that frame
ChromeFindElements>session_id,xpath,//span[@id='interactions-label'],lblInteractions
ChromeElementAction>session_id,lblInteractions_1,click
Can you tell me what is wrong with those instructions?

Thank you so much for your help.

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1386
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Iterate Chrome page variable buttons

Post by Dorian (MJT support) » Sun Nov 07, 2021 1:24 pm

If you're trying to click on the part you've highlighted shouldn't you be using div, id, and interactions-main-menu-item.

Also are you sure elements_3 is the correct frame?

Apologies for the oddly formatted reply, I'm answering from my phone.
Yes, we have a Custom Scripting Service. Message me or go here

drunkenmonkey
Pro Scripter
Posts: 90
Joined: Fri Jan 31, 2020 10:52 am

Re: Iterate Chrome page variable buttons

Post by drunkenmonkey » Sun Nov 07, 2021 3:03 pm

Thank you for your answer Dorian!
I did adjust the instructions. Here's a capture of it.
https://u.pcloud.link/publink/show?code ... ACpmdoo4hX
The lblInteractions result = 0.

Thank you so much for your help!

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1386
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Iterate Chrome page variable buttons

Post by Dorian (MJT support) » Sun Nov 07, 2021 3:20 pm

Can you post the HTML as well as the photos. Tech support with screenshots can be less than ideal at times. Just pasting it as code here is fine. That html document you uploaded further up this thread didn't seem to work.
Yes, we have a Custom Scripting Service. Message me or go here

drunkenmonkey
Pro Scripter
Posts: 90
Joined: Fri Jan 31, 2020 10:52 am

Re: Iterate Chrome page variable buttons

Post by drunkenmonkey » Sun Nov 07, 2021 3:32 pm

Thank you for your reply Dorian!
Here's a piece of the code behind this frame.
https://u.pcloud.link/publink/show?code ... L2J0Krh9RV
And the page photo.
https://u.pcloud.link/publink/show?code ... sBxXSlM237
Thank you for you help!

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1386
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Iterate Chrome page variable buttons

Post by Dorian (MJT support) » Mon Nov 08, 2021 10:53 am

I used :

Code: Select all

ChromeFindElements>session_id,xpath,//span[@id='interactions-label'],lblInteractions
..and lblInteractions_count was 1.

But of course we can probably expect that because the html we're using is already working with the correct frame - it's simply the contents of the frame.

So this leads me to believe you're not switching to the correct frame. When you switch frame using elements_3 your result of 0 is showing you've successfully switched frame - but that doesn't mean it's the correct frame.

This looks odd to me : //SCRIPT[@src='_SupportFiles/common.js']
Shouldn't the tag be "FRAME" OR "IFRAME" ?

I'm happy to look at this for you if you can send the access credentials for this to us at support.
Yes, we have a Custom Scripting Service. Message me or go here

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1386
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Iterate Chrome page variable buttons

Post by Dorian (MJT support) » Mon Nov 08, 2021 11:21 am

You can also switch frame by index. This may be easier. You can even loop through all the frames looking for your element. This will loop through the frames and tell you which frame it finds your element. It stops at 100 frames so it's not an endless loop. If it finds the element it will construct the correct ChromeSwitchFrame code for you.

This should work for any site, all you need to do is edit the ChromeFindElements line accordingly.

Code: Select all

Let>el_count=0
Let>LoopCount=0
While>el_count=0
  Let>LoopCount=LoopCount+1
  
  //Switch frame
  ChromeSwitchFrame>session_id,index,LoopCount,res
  
  //Look for this element :
  ChromeFindElements>session_id,xpath,//span[@id='interactions-label'],el
  
  //Switch back
  ChromeSwitchFrame>session_id,index,null,res

  If>el_count>0
    MDL>element found in frame %LoopCount%.%CRLF%%CRLF%Use :%CRLF%%CRLF%ChromeSwitchFrame>session_id,index,%LoopCount%,res%CRLF%%CRLF%This has been copied to clipboard
    Let>ScriptLine=ChromeSwitchFrame>session_id,index,%LoopCount%,res
    Put>ScriptLine
    Exit
  Endif
  
    
  if>LoopCount>100
    mdl>Searched 100 frames and didn't find it
    Exit
  Endif

Endwhile
Yes, we have a Custom Scripting Service. Message me or go here

drunkenmonkey
Pro Scripter
Posts: 90
Joined: Fri Jan 31, 2020 10:52 am

Re: Iterate Chrome page variable buttons

Post by drunkenmonkey » Mon Nov 08, 2021 11:40 am

Thank you Dorian for your help!
I sent a PM message. Can you confirm reception?
Thank you!

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1386
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Iterate Chrome page variable buttons

Post by Dorian (MJT support) » Mon Nov 08, 2021 2:34 pm

Mystery solved.

The item in question was in a new tab that had been opened by a previous button click. It was also in a frame.

So the solution was to switch focus and then switch frames. Index,0 was the solution there.

Code: Select all

ChromeSwitchFrame>session_id,index,0,a1
ChromeFindElements>session_id,xpath,//div[@id='interactions-main-menu-item'],lbl1
ChromeElementAction>session_id,lbl1_1,click
Yes, we have a Custom Scripting Service. Message me or go here

drunkenmonkey
Pro Scripter
Posts: 90
Joined: Fri Jan 31, 2020 10:52 am

Re: Iterate Chrome page variable buttons

Post by drunkenmonkey » Wed Nov 10, 2021 9:35 pm

Hi Dorian and thank you so much for your help.
I have run your solution with success.

Have a great day and sorry I couldn't get back with a response before today.

:D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts