Click on any link in the page but one

DBG

New Member
VIP
Joined
Mar 2, 2021
Messages
12
Reaction score
0
Achievement
Hello.
Maybe I can get some help from one of you regarding this problem:

Say I have a web page which contains the following internal links:


I want to run a macro that will click in any of those internal links but #1 or #4 (say they are non profitable ones that must be included in the page anyway: privacy notice, legal things, etc).

I need the solution to be based in filtering by link text (even if it requires nexted "ifs"), since the position of links 1 and 4 may be different in another page.
Can this be done with the set of macro functions we have available?

Thanks in advance!!
 

opsfafsme

Well-Known Member
Rule The Universe
VIP
Joined
Jul 2, 2018
Messages
243
Reaction score
91
Website
OnlinePiercingShop.com
Achievement
Hello.
Maybe I can get some help from one of you regarding this problem:

Say I have a web page which contains the following internal links:


I want to run a macro that will click in any of those internal links but #1 or #4 (say they are non profitable ones that must be included in the page anyway: privacy notice, legal things, etc).

I need the solution to be based in filtering by link text (even if it requires nexted "ifs"), since the position of links 1 and 4 may be different in another page.
Can this be done with the set of macro functions we have available?

Thanks in advance!!
when you say " based in filtering by link text" do you mean part of url or is it exactly the link text

<a href=''.../part of url">link text</a>
 

DBG

New Member
VIP
Joined
Mar 2, 2021
Messages
12
Reaction score
0
Achievement
Initially I was thinking of part of the url, but the other option could also be interesting since It could give me the chance to write the link texts in a way that a given string is present in the text of all the links that I want the macro to click.
 

opsfafsme

Well-Known Member
Rule The Universe
VIP
Joined
Jul 2, 2018
Messages
243
Reaction score
91
Website
OnlinePiercingShop.com
Achievement
Initially I was thinking of part of the url, but the other option could also be interesting since It could give me the chance to write the link texts in a way that a given string is present in the text of all the links that I want the macro to click.
if as a part of url it is quite simple
JavaScript:
await Delay(Random(2500,3000));
await WaitForLoading();

var random_url, myTargetXpath, foundLink;

// an array of url_parts one of which needs to be clicked
var unique_url_parts = [
    "planes",
    "boats",
    "cars"
];

random_url = Math.floor(Math.random() * unique_url_parts.length);    //choose a random url for a click

myTargetXpath = GenerateXpath("a", "href", "%" + unique_url_parts[random_url] + "%");
foundLink = await GetAttribute(myTargetXpath, "href");
if ( foundLink ) {
    await ClickByXpath(myTargetXpath);
} else {
    // error - for some reason the link was not found
}
The second option is a little more complicated but also not something supernatural.
 
Last edited:
  • Like
Reactions: cucaibap

DBG

New Member
VIP
Joined
Mar 2, 2021
Messages
12
Reaction score
0
Achievement
Ok, thanks!!!!!
I'll give it a try.
 

About us

  • Our community has been around for many years and pride ourselves on offering unbiased, critical discussion among people of all different backgrounds. We are working every day to make sure our community is one of the best.

Quick Navigation

User Menu