You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* temporatily do not look at unsuccessful but detected cases
* Use a built-in escape function
* Add a note about auto-generated rules
* add data-testid
* do not scrape buttons with empty text
* verify self-test in generated rules
* Lint fix
* prettify the output
@@ -257,19 +254,30 @@ function getUniqueSelector(el) {
257
254
// We need to strike a balance here. Selector has to be unique, but we want to avoid auto-generated (randomized) identifiers to make the it resilient. Assumptions:
258
255
// - Classes are the most common thing to randomize, so we use them as the last resort.
259
256
// - The general shape of the DOM doesn't change that much, so order is always preferred
260
-
// - data attributes can contain anything, so don't add them by default
261
-
// - IDs are often used on the popup containers, so are very useful. And they are definitely less commonly randomized than classes, but it's still possible, so we may want to change this logic later if we see randomized ids in the results.
257
+
// - data attributes can contain anything, so don't add them by default (except for data-testid, which is usually fine)
258
+
// - IDs are often used on the popup containers, so are very useful. Sometimes they are randomized too, but it's not as common.
262
259
constspecificity={
260
+
testid: true,
261
+
ids: true,
263
262
order: true,
264
-
ids: true,// consider disabling this by default for auto-generated IDs
265
263
dataAttributes: false,
266
264
classes: false,
267
265
absoluteOrder: false,
268
266
};
269
267
letselector=getSelector(el,specificity);
270
268
269
+
// increase specificity until the selector is unique
271
270
try{
272
-
// verify that the selector is unique
271
+
if(document.querySelectorAll(selector).length>1){
272
+
specificity.order=true;
273
+
selector=getSelector(el,specificity);
274
+
}
275
+
276
+
if(document.querySelectorAll(selector).length>1){
277
+
specificity.ids=true;
278
+
selector=getSelector(el,specificity);
279
+
}
280
+
273
281
if(document.querySelectorAll(selector).length>1){
274
282
specificity.dataAttributes=true;
275
283
selector=getSelector(el,specificity);
@@ -301,7 +309,7 @@ function getUniqueSelector(el) {
0 commit comments