Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

NoSuchElementException not getting the exception #759

Answered by mdmintz
acpn asked this question in Q&A
Discussion options

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

You must be logged in to vote

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

Comment options

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.

You must be logged in to vote
1 reply
Comment options

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!!

Answer selected by mdmintz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /