Skip to content

Commit 88ff127

Browse files
committed
Recorder: Skip 'aria-label' & 'for' attributes containing numbers
1 parent 7ecd1bc commit 88ff127

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

seleniumbase/js_code/recorder_js.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@
106106
}
107107
return n;
108108
};
109+
function hasNumber(str) {
110+
return /\d/.test(str);
111+
};
109112
var getBestSelector = function(el) {
110113
if (!(el instanceof Element))
111114
return;
@@ -155,18 +158,22 @@
155158
num_by_attr = [];
156159
child_count_by_attr = [];
157160
for (var i = 0; i < non_id_attributes.length; i++) {
161+
n_i_attr = non_id_attributes[i];
158162
selector_by_attr[i] = null;
159-
if (non_id_attributes[i] == 'class') {
163+
if (n_i_attr == 'class') {
160164
selector_by_attr[i] = selector_by_class;
161165
}
162166
else {
163-
selector_by_attr[i] = cssPathByAttribute(el, non_id_attributes[i]);
167+
selector_by_attr[i] = cssPathByAttribute(el, n_i_attr);
164168
}
165169
all_by_attr[i] = document.querySelectorAll(selector_by_attr[i]);
166170
num_by_attr[i] = all_by_attr[i].length;
167171
if (!selector_by_attr[i].includes(child_sep) &&
168172
((num_by_attr[i] == 1) || (el == all_by_attr[i][0])))
169173
{
174+
if (n_i_attr == 'aria-label' || n_i_attr == 'for')
175+
if (hasNumber(selector_by_attr[i]))
176+
continue;
170177
return selector_by_attr[i];
171178
}
172179
child_count_by_attr[i] = ssOccurrences(selector_by_attr[i], child_sep);

0 commit comments

Comments
 (0)