Overall, I have been loving the CSS Selector feature. Unfortunately, I find myself needing to copy and paste nearly identical selectors frequently, and then editing them all one after another. Is there a way to have it so I can set the value of the selector via a formula or variable, then reference it within the Website or Click command?
Hi @Patrick_van_Duyse Welcome to the forum!
Your observation is correct sadly there is no way to do that as of now. I think we would definitely want to do it - the only constraint is that the chain of dependent variables should be constant strings.
For example: if selector A depends on var A, which depends on var B, then var B should be an exact assignment ({varB="#some-selector"}
) rather than being a dynamic input ({formtext: name=varB}
).
That absolutely makes sense, and frankly, even that would be fantastic.
A couple of use cases for the use of constant string variables in CSS selectors:
- There is a specific website that I use for which every single selector needs to start with the exact same string. This string is not short. Being able to reference this string using a couple of characters would make the different selectors much more distinct and readable.
- There are cases where I need to get 3 to 5 specific descendent elements (ie name, timestamp, content) of each parent element that matches a specific selector. This usually means having 3 to 5 website commands (one for each descendent element) then mapping the resulting arrays into a 2D array (it's much easier than pulling the full HTML for the parent element and using regex to parse it). However, it can be a pain to setup/adjust/debug as anytime I want to tweak the portion of the selector that determines which parent element I'm including, I need to apply that same tweak to each of the website commands.
- If I have very repetitive snippets, I'll often make a core snippet that holds all of the repeated bits and then is imported into multiple (now short) snippets. This allows me to have each snippet set a sequence of variables, which are then referenced in the code imported from the core snippet. This doesn't work (right now) if the bit that varies is within a selector.
If this helps, I ask the AI Write feature on TB (or any chatGPT variation works) to finish up my repetitive snippets.
E.g, I asked it to finishing numbering a list of CSS selector data elements #1-85
Hi @PQN can you please share your snippet where you are using 85 CSS selectors that are roughly the same except their number parts? There might be better ways to achieve the same result.