Is this possible with UI vision?

I’m trying to make a simple ish macro that will click on links but not if the link its about to click on has red font. In that case, it will skip to the next link, checking to see if that has red font. If not, it clicks it etc.

I thougth storeAttribute would accomplish this but I’m not certain. The links themselves have been individually styled by some script.

If you need to create an autoclicker for ptc usually the code is masked to prevent bot

So does that mean I have to use some OCR and actually look for the color red? Seems unreliable

This is a good idea. Do you have a website link for us to test?

If that fails, XClick can probably solve it with image recognition.

I can’t really link the page since its through a secured login but I can give you most of the code around the items.

<span onclick="if (!$(this).attr('disabled')) { AddOrderChoiceRow(926,31,2, null, 0); }" id="ComponentGroupItem_31_926_2" class="componentSpan Selected" compid="926" cgpid="31" descriptiontext="" style="cursor:pointer;color:Red;font-weight:normal;">RS Spaghetti (tinned)</span>

The unique code for that item is the component group item number, but it should skip the click if it detects the style having that red color. It means they’re allergic to that food and it would be dangerous to click that!

Do you want a macro that clicks ALL non-red links on the page? If so, it would need to click, then come back to the current tab, click the next, back to the current tab, and so on correct?

Or are you just trying to make a macro that clicks the first non-red link and then stops?

Nah, not all, specific links. If it detects they have red font, skip them and move on to the next. At most, it will click about 3-4 total.

OK, this might work provided everything adheres to your example. But without an actual place for me to run tests I can’t guarantee you anything.

{
  "Command": "executeScript",
  "Target": "var spans = document.getElementsByTagName(\"SPAN\"), spanArray = new Array();for (let i=0;i<spans.length;i++){if (spans[i].style.color != 'Red'){spanArray.push(spans[i].id)}} return spanArray",
  "Value": "links"
},
{
  "Command": "forEach",
  "Target": "links",
  "Value": "n"
},
{
  "Command": "executeScript",
  "Target": "document.getElementById(${n}).click()",
  "Value": ""
},
{
  "Command": "selectWindow",
  "Target": "tab=0",
  "Value": ""
},
{
  "Command": "end",
  "Target": "",
  "Value": ""
}

That looks fantastic, I can’t wait to try it. However, forgive my ignorance, where in that code do I specifiy the items I wish clicked? I see the checking going on if they’re red and the fail state of that(
if (spans[i].style.color != ‘Red’)

but honestly this looks like javascript now and I suppose thats what is needed. It seems like this code will click everything not Red fonted

Yep, I use lots of Javascript in my macros. It adds a huge amount of versatility. To break it down, my first executeScript code gets every “span” element on the page, then creates a new, empty array. It then loops over each span, and if the color is not red, it pushes the span’s ID to the array.

So now we have a list of span IDs that have non-red font stored in the variable “links.” We use forEach to iterate through the list. I use executeScript again here (there’s a typo in my original code, see below) to simulate a click on the elements with the IDs we’ve put in the list. We then come back to the original tab we started in and move to the next link.

My apologies, but I accidentally put {id} in the executeScript command that's under the forEach. Please change that to {n} if you’ve already copied my code.

Thats great, thanks for your work. The links in question don’t actually open a new tab, they just select items to add to a list, specifically a menu order.

It does currently return an error:

[error]

[Line 3]: Error in executeScript code: Cannot read property ‘click’ of null

I think i’ve not added exactly the id’s I wish it to click, is that correct?

Ah, it didn’t like my use of “n” as the variable in that forEach loop. Whoops. Swap it out with the below code and you’ll be good. There’s also a teak in the top command. Depending on your page, there might be other validation you could put in here, but this should do the trick.

{
  "Command": "executeScript",
  "Target": "var spans = document.getElementsByTagName(\"SPAN\"), spanArray = new Array();for (let i=0;i<spans.length;i++){if (spans[i].style.color != 'Red' && spans[i].id){spanArray.push(spans[i].id)}} return spanArray",
  "Value": "links"
},
{
  "Command": "forEach",
  "Target": "links",
  "Value": "spanId"
},
{
  "Command": "executeScript",
  "Target": "document.getElementById(${spanId}).click()",
  "Value": ""
},
{
  "Command": "end",
  "Target": "",
  "Value": ""
}

The code you’re posted does work, but it works a bit too well. It just selects everything on the page, when I was only looking for it to click specific things :stuck_out_tongue:
Can I possibly add in specific things into the array that still get dropped from it if they have the red font? Or am I supposed to add something to the click event itself that attempts to only refer to the array and if its not there, skip to the next in that array?

To make that more concrete, the list of links are menu items, so im just trying to prevent your code from selecting everything on the menu heh

Darn! It’s supposed to only add the Element ID if the element’s font does not equal Red. Unfortunately, without page access I won’t really be able to see where exactly it’s failing.

Its accomplishing exactly that. The problem is not in the selection itself, but in its scope. There are alot of non-red things for it to add to the array, but I’m only trying to add specific things to the array and avoid the red ones at the same time. Is that possible?

<span onclick="if (!$(this).attr('disabled')) { AddOrderChoiceRow(926,31,2, null, 0); }" id="ComponentGroupItem_31_926_2" class="componentSpan Selected" compid="926" cgpid="31" descriptiontext="" style="cursor:pointer;color:Red;font-weight:normal;">RS Spaghetti (tinned)</span>

In my rough idea, I wanted:
id="ComponentGroupItem_31_926_2"
id="ComponentGroupItem_31_918_2"
id="ComponentGroupItem_31_908_2"

added to the array, but since 31_918_2 was red, it wasn’t added, and then the remaining two were clicked.

Ah, got it! It’s like having a special marker for ingredients in the best barbacoa in San Antonio. If it detects that red color style, it’s like signaling a potential allergy—definitely a no-go for clicking! Safety first, just like being cautious with certain ingredients in cooking, especially when someone has an allergy.