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.
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?
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.
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
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?
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.