-
Notifications
You must be signed in to change notification settings - Fork 1.4k
-
Hi guys,
I'm building an crawler to get some information's about companies in facebook, and sometimes companies doesn' t have a page in that case I check for specific tag in the DOM. When I did this check:
def try_or_pass(self, selector, timeout=None):
extracted_info = ''
try:
if timeout:
extracted_info = self.get_text(selector=selector,
timeout=timeout)
else:
extracted_info = self.get_text(selector=selector)
except:
logging.error('Element ' + selector + ' not found.')
return extracted_info
My expectations was to falls in the except part, log the error and then return my extracted_info variable empty, however the get_text method falls in NoSuchElementException and my except will never be executed. I try another methods from seleniumbase but always falls in the same problem, could someone help me?
Thanks,
Antonio
Beta Was this translation helpful? Give feedback.
All reactions
Hi @acpn , the try/except block should be catching exceptions... which line is the test failing on when you run it? Have you tried using except Exception:
instead? Is it possible that the test failed before it reached this line? SeleniumBase produces screenshots so that you can verify that you're on the correct page. See the latest_logs/
folder that's created when you run your test. You can also do --html=report.html
to generate an html report, which also has screenshots.
Replies: 1 comment 1 reply
-
Hi @acpn , the try/except block should be catching exceptions... which line is the test failing on when you run it? Have you tried using except Exception:
instead? Is it possible that the test failed before it reached this line? SeleniumBase produces screenshots so that you can verify that you're on the correct page. See the latest_logs/
folder that's created when you run your test. You can also do --html=report.html
to generate an html report, which also has screenshots.
Beta Was this translation helpful? Give feedback.
All reactions
-
Thank you @mdmintz, when you mentioned about the error reaching out before/after this point i found my mistake. I'm using inheritance and I was overriding an method without realize that. So when finish the first execution the method calls herself again like an recursive method and the tags I was trying to insert some text doesn't exists in the page I was crawling.
The reports also helps a lot, great project man, cheers!!
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1 -
🎉 1