|
109 | 109 | function hasNumber(str) {
|
110 | 110 | return /\d/.test(str);
|
111 | 111 | };
|
| 112 | +function tagName(el) { |
| 113 | + return el.tagName.toLowerCase(); |
| 114 | +}; |
112 | 115 | var getBestSelector = function(el) {
|
113 | 116 | if (!(el instanceof Element))
|
114 | 117 | 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 | + } |
115 | 124 | child_sep = ' > ';
|
116 | 125 | selector_by_id = cssPathById(el);
|
117 | 126 | if (!selector_by_id.includes(child_sep))
|
118 | 127 | return selector_by_id;
|
119 | 128 | child_count_by_id = ssOccurrences(selector_by_id, child_sep);
|
120 | 129 | selector_by_class = cssPathByClass(el);
|
121 |
| - tag_name = el.tagName.toLowerCase(); |
| 130 | + tag_name = tagName(el); |
122 | 131 | non_id_attributes = [];
|
123 | 132 | non_id_attributes.push('name');
|
124 | 133 | non_id_attributes.push('data-qa');
|
|
230 | 239 | }
|
231 | 240 | }
|
232 | 241 | }
|
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 |
| - } |
258 | 242 | best_selector = selector_by_id;
|
259 | 243 | lowest_child_count = child_count_by_id;
|
260 | 244 | child_count_by_class = ssOccurrences(selector_by_class, child_sep);
|
|
0 commit comments