From 2c764e8f84aba19fa865e19c623689646034958b Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Tue, 29 Nov 2022 08:46:11 +0100 Subject: [PATCH] BrowserSteps - Also try to find clickable div/spans --- changedetectionio/blueprint/browser_steps/browser_steps.py | 2 +- changedetectionio/res/xpath_element_scraper.js | 4 +++- changedetectionio/static/js/browser-steps.js | 6 +----- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/changedetectionio/blueprint/browser_steps/browser_steps.py b/changedetectionio/blueprint/browser_steps/browser_steps.py index b6a7af08..5cf7c066 100644 --- a/changedetectionio/blueprint/browser_steps/browser_steps.py +++ b/changedetectionio/blueprint/browser_steps/browser_steps.py @@ -232,7 +232,7 @@ class browsersteps_live_ui(steppable_browser_interface): self.page.evaluate("var include_filters=''") # Go find the interactive elements # @todo in the future, something smarter that can scan for elements with .click/focus etc event handlers? - elements = 'a,button,input,select,textarea,i,th,td,p,li,h1,h2,h3,h4' + elements = 'a,button,input,select,textarea,i,th,td,p,li,h1,h2,h3,h4,div,span' xpath_element_js = xpath_element_js.replace('%ELEMENTS%', elements) xpath_data = self.page.evaluate("async () => {" + xpath_element_js + "}") # So the JS will find the smallest one first diff --git a/changedetectionio/res/xpath_element_scraper.js b/changedetectionio/res/xpath_element_scraper.js index 743e1f5d..193453c7 100644 --- a/changedetectionio/res/xpath_element_scraper.js +++ b/changedetectionio/res/xpath_element_scraper.js @@ -124,6 +124,7 @@ for (var i = 0; i < elements.length; i++) { continue; } + // @todo Possible to ONLY list where it's clickable to save JSON xfer size size_pos.push({ xpath: xpath_result, width: Math.round(bbox['width']), @@ -131,7 +132,8 @@ for (var i = 0; i < elements.length; i++) { left: Math.floor(bbox['left']), top: Math.floor(bbox['top'])+scroll_y, tagName: (elements[i].tagName) ? elements[i].tagName.toLowerCase() : '', - tagtype: (elements[i].tagName == 'INPUT' && elements[i].type) ? elements[i].type.toLowerCase() : '' + tagtype: (elements[i].tagName == 'INPUT' && elements[i].type) ? elements[i].type.toLowerCase() : '', + isClickable: (elements[i].onclick) || window.getComputedStyle(elements[i]).cursor == "pointer" }); } diff --git a/changedetectionio/static/js/browser-steps.js b/changedetectionio/static/js/browser-steps.js index acef6fb9..efd6b71f 100644 --- a/changedetectionio/static/js/browser-steps.js +++ b/changedetectionio/static/js/browser-steps.js @@ -196,9 +196,7 @@ $(document).ready(function () { $('input[placeholder="Value"]', first_available).addClass('ok').click().focus(); found_something = true; } else { - // Assume it's just for clicking on - // what are we clicking on? - if (x['tagName'].startsWith('h')|| x['tagName'] === 'a' || x['tagName'] === 'button' || x['tagtype'] === 'submit'|| x['tagtype'] === 'checkbox'|| x['tagtype'] === 'radio'|| x['tagtype'] === 'li') { + if (x['isClickable'] || x['tagName'].startsWith('h')|| x['tagName'] === 'a' || x['tagName'] === 'button' || x['tagtype'] === 'submit'|| x['tagtype'] === 'checkbox'|| x['tagtype'] === 'radio'|| x['tagtype'] === 'li') { $('select', first_available).val('Click element').change(); $('input[type=text]', first_available).first().val(x['xpath']); found_something = true; @@ -220,8 +218,6 @@ $(document).ready(function () { } } } - } else { - } }