diff --git a/changedetectionio/html_tools.py b/changedetectionio/html_tools.py
index 6b73e5d1..e9e0023f 100644
--- a/changedetectionio/html_tools.py
+++ b/changedetectionio/html_tools.py
@@ -21,7 +21,7 @@ def css_filter(css_filter, html_content):
soup = BeautifulSoup(html_content, "html.parser")
html_block = ""
r = soup.select(css_filter, separator="")
- if len(r) == 0:
+ if len(html_content) > 0 and len(r) == 0:
raise FilterNotFoundInResponse(css_filter)
for item in r:
html_block += str(item)
@@ -49,8 +49,8 @@ def xpath_filter(xpath_filter, html_content):
html_block = ""
r = tree.xpath(xpath_filter.strip(), namespaces={'re': 'http://exslt.org/regular-expressions'})
- if len(r) == 0:
- raise FilterNotFoundInResponse(css_filter)
+ if len(html_content) > 0 and len(r) == 0:
+ raise FilterNotFoundInResponse(xpath_filter)
for item in r:
html_block += etree.tostring(item, pretty_print=True).decode('utf-8') + "
"
diff --git a/changedetectionio/tests/test_filter_failure_notification.py b/changedetectionio/tests/test_filter_failure_notification.py
index 17dff1f3..c2bbe296 100644
--- a/changedetectionio/tests/test_filter_failure_notification.py
+++ b/changedetectionio/tests/test_filter_failure_notification.py
@@ -22,12 +22,7 @@ def set_response_with_filter():
f.write(test_return_data)
return None
-
-# Hard to just add more live server URLs when one test is already running (I think)
-# So we add our test here (was in a different file)
-def test_check_notification(client, live_server):
- live_server_setup(live_server)
- set_original_response()
+def run_filter_test(client, content_filter):
# Give the endpoint time to spin up
time.sleep(1)
@@ -72,7 +67,7 @@ def test_check_notification(client, live_server):
"tag": "my tag",
"title": "my title",
"headers": "",
- "css_filter": '#nope-doesnt-exist',
+ "css_filter": content_filter,
"fetch_backend": "html_requests"})
res = client.post(
@@ -99,7 +94,7 @@ def test_check_notification(client, live_server):
with open("test-datastore/notification.txt", 'r') as f:
notification = f.read()
assert 'CSS/xPath filter was not present in the page' in notification
- assert '#nope-doesnt-exist' in notification
+ assert content_filter.replace('"', '\\"') in notification
# Remove it and prove that it doesnt trigger when not expected
os.unlink("test-datastore/notification.txt")
@@ -121,3 +116,19 @@ def test_check_notification(client, live_server):
url_for("form_delete", uuid="all"),
follow_redirects=True
)
+ os.unlink("test-datastore/notification.txt")
+
+
+def test_setup(live_server):
+ live_server_setup(live_server)
+
+def test_check_css_filter_failure_notification(client, live_server):
+ set_original_response()
+ time.sleep(1)
+ run_filter_test(client, '#nope-doesnt-exist')
+
+def test_check_xpath_filter_failure_notification(client, live_server):
+ set_original_response()
+ time.sleep(1)
+ run_filter_test(client, '//*[@id="nope-doesnt-exist"]')
+