Button click loop / skip pages that don't have click button with attributes

I have a problem, I can’t find help here on the forum.

What I need to do is the following.
Summary: Accessing links, clicking buttons, doing it in a loop, 24/7

How it works:

  1. access link
  2. Search the site, if there is any button with the attributes.
  3. click on all the buttons that have the attribute.
  4. exit page, enter another page, loop.

Difficulty:
Some pages have 5 buttons, some have 100, some have 1, and some have 0 buttons.

How to ignore pages with 0 buttons?
Is there a way before starting to click, check if the page has the buttons?

Currently my script clicks 100 times, I have "errorignore"
I want to prevent the script from trying to click, and jump to the next page.

{
  "Name": "forum",
  "CreationDate": "2022-3-9",
  "Commands": [
    {
      "Command": "store",
      "Target": "true",
      "Value": "!errorignore",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "fast",
      "Value": "!REPLAYSPEED",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "1",
      "Value": "!TIMEOUT_WAIT",
      "Description": ""
    },
    {
      "Command": "open",
      "Target": "https://exemple.com/downloads-pictures",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "xpath=//div[2]/div/div/div/div/div/div",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "xpath=//td[8]/a/i",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "xpath=//tr[2]/td[8]/a/i",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "xpath=//tr[3]/td[8]/a/i",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "xpath=//tr[4]/td[8]/a/i",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "xpath=//tr[5]/td[8]/a/i",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "xpath=//tr[6]/td[8]/a/i",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "xpath=//tr[7]/td[8]/a/i",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "comment",
      "Target": "....keep going up to 100",
      "Value": "....keep going up to 100",
      "Description": ""
    },
    {
      "Command": "",
      "Target": "",
      "Value": "",
      "Description": ""
    }
  ]
}

Do you have links to a few sample websites?

2 Likes

I would say that if the number of buttons is different from each other site, then the sourceSearch and the sourchExtract would help. I don’t have your exactly web, but I would do something like:

Check the source code of a button. See if there’s a mutual code that is the same between other buttons but is different from other element of the site.

Use sourceSearch to count the number of that. If the number = 0, then you move to the next loop.

Depending on the script you provided, I assume you try td[8]/a/i, but it’s just a guess, normally it would be something that’s a bit more complicated. You should try and test as many as you can to see if your guess is correct or not.

And beside, I suggest you try to do awhile loop command, because all your clicking xpaths are the same, but the number in the first place. So I would do something like this:

sourceSearch | xpath for buttons | countingVar
if_v2 | ${countingVar} == 0
gotoLabel | next
else
times | ${countingVar}
click | xpath=//tr[${beginVar}]/td[8]/a/i
executeScript_sandbox | return Number(${beginVar})+1 | ${beginVar}
end
end
label | next

Of course the exact grammar might be a bit more, but it’s the idea. So if the number of button is equal 0, it’s going to skip the clicking part.

1 Like

{
“Command”: “storeXpathCount”,
“Target”: “xpath=//tr”,
“Value”: “Count”,
“Description”: “”
},
{
“Command”: “times”,
“Target”: “${Count}”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “click”,
“Target”: “xpath=//tr[${!times}]/td[8]/a/i”,
“Value”: “”,
“Description”: “”
},
{
“Command”: “end”,
“Target”: “”,
“Value”: “”,
“Description”: “”
}

1 Like

Thanks for the help guys, I’m learning to program with the advice here on the forum.

@ulrich can’t share here, they are internal pages of my work.

@kolor_blind kolor_blind this tip is great, it worked well, I was doing tests before posting an answer here, it will help me in other projects, thanks.

@uiuser uiuser those lines of code didn’t know, this way of doing “internal loop” is very easy, your solution worked too. I was having problems generating a loop on the same button, I was trying to put “click | xpath=//td[8]/a/i@POS=${!LOOP}” (but I didn’t understand where the error was)

That way “click | xpath=//tr[${!times}]/td[8]/a/i” worked perfectly.

I made some changes, now less lines, I ended up leaving the “loop at 100”, until I jumped to the next page.

{
  "Name": "FORUM KANTU",
  "CreationDate": "2022-3-12",
  "Commands": [
    {
      "Command": "bringBrowserToForeground",
      "Target": "",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "open",
      "Target": "https://www.exemple.com/page",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "times",
      "Target": "10",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "true",
      "Value": "!errorignore",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "medium",
      "Value": "!REPLAYSPEED",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "1",
      "Value": "!TIMEOUT_WAIT",
      "Description": ""
    },
    {
      "Command": "times",
      "Target": "100",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "clickAndWait",
      "Target": "xpath=//tr[${!times}]/td[8]/a/i",
      "Value": "",
      "Description": "site 01"
    },
    {
      "Command": "pause",
      "Target": "3000",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "end",
      "Target": "",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "pause",
      "Target": "3000",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "linkText=next page",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "end",
      "Target": "",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "comment",
      "Target": "end // ",
      "Value": "",
      "Description": ""
    }
  ]
}

This is the result I’m using now.
Thanks guys, I have another question, but I’ll open another topic here on the forum.

ps: I’m trying to learn, but I’m also willing to hire someone to help me, if you’re interested, send me a private message. thanks

@pos dont work with xpath

!errorignore
!REPLAYSPEED
!TIMEOUT_WAIT

if you place these lines above First Times command
then it will be faster

for

{
“Command”: “times”,
“Target”: “100”,
“Value”: “”,
“Description”: “”
}

try this

{
“Command”: “storeXpathCount”,
“Target”: “xpath=//tr”,
“Value”: “Count”,
“Description”: “”
},
{
“Command”: “times”,
“Target”: “${Count}”,
“Value”: “”,
“Description”: “”
}

because if there are less than 100 then you will be wasting 1 second per link

You might to edit xpath