Skip to content

Commit 69b7bc2

Browse files
committed
Recorder: If the element is a span of a button, use the button
1 parent afc8002 commit 69b7bc2

File tree

1 file changed

+10
-26
lines changed

1 file changed

+10
-26
lines changed

seleniumbase/js_code/recorder_js.py

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,25 @@
109109
function hasNumber(str) {
110110
return /\d/.test(str);
111111
};
112+
function tagName(el) {
113+
return el.tagName.toLowerCase();
114+
};
112115
var getBestSelector = function(el) {
113116
if (!(el instanceof Element))
114117
return;
118+
if (tagName(el) == 'span') {
119+
if (tagName(el.parentElement) == 'button')
120+
el = el.parentElement;
121+
else if (tagName(el.parentElement.parentElement) == 'button')
122+
el = el.parentElement.parentElement;
123+
}
115124
child_sep = ' > ';
116125
selector_by_id = cssPathById(el);
117126
if (!selector_by_id.includes(child_sep))
118127
return selector_by_id;
119128
child_count_by_id = ssOccurrences(selector_by_id, child_sep);
120129
selector_by_class = cssPathByClass(el);
121-
tag_name = el.tagName.toLowerCase();
130+
tag_name = tagName(el);
122131
non_id_attributes = [];
123132
non_id_attributes.push('name');
124133
non_id_attributes.push('data-qa');
@@ -230,31 +239,6 @@
230239
}
231240
}
232241
}
233-
if (tag_name == "span" && inner_text.length > 1 && inner_text.length <= 64)
234-
{
235-
parent_element = el.parentElement;
236-
parent_tag_name = parent_element.tagName.toLowerCase();
237-
grand_element = parent_element.parentElement;
238-
grand_tag_name = grand_element.tagName.toLowerCase();
239-
if (parent_tag_name == "button" || grand_tag_name == "button") {
240-
qsa_element = "span";
241-
if (parent_tag_name == "button")
242-
qsa_element = "button > span";
243-
else
244-
qsa_element = "button > "+parent_tag_name+" > span";
245-
t_count = 0;
246-
all_el_found = document.querySelectorAll(qsa_element);
247-
for (var j = 0; j < all_el_found.length; j++) {
248-
if (all_el_found[j].innerText.includes(inner_text))
249-
t_count += 1;
250-
}
251-
if (t_count === 1 && !inner_text.includes('\n')) {
252-
inner_text = inner_text.replaceAll("'", "\\'");
253-
inner_text = inner_text.replaceAll('"', '\\"');
254-
return qsa_element += ':contains("'+inner_text+'")';
255-
}
256-
}
257-
}
258242
best_selector = selector_by_id;
259243
lowest_child_count = child_count_by_id;
260244
child_count_by_class = ssOccurrences(selector_by_class, child_sep);

0 commit comments

Comments
 (0)