Put except with bug name in python

Asked

Viewed 222 times

-1

I need to create a Try except, with two excepts, but do not know how to put the specific error in the first except, the error that appears this below, someone could help me?

 raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Element <div class="card-servicos-destaque" ng-style="card.estilo" style="background-color: rgb(237, 28, 36);">...</div> is not clickable at point (136, 346). Other element would receive the click: <div uib-modal-window="modal-window" class="modal fade ng-scope ng-isolate-scope" role="dialog" aria-labelledby="modal-title" aria-describedby="modal-body" index="0" animate="animate" ng-style="{'z-index': 1050 + $$topModalIndex*10, display: 'block'}" tabindex="-1" uib-modal-animation-class="fade" modal-in-class="in" modal-animation="true" style="z-index: 1050; display: block;">...</div>
  (Session info: chrome=70.0.3538.67)
  (Driver info: chromedriver=2.42.591088 (7b2b2dca23cca0862f674758c9a3933e685c27d5),platform=Windows NT 10.0.17134 x86_64)

And this:

raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Element <button ng-click="vm.irParaHistoricoDeContas()" type="submit" class="btn btn-link btn-lg btn-block ng-scope" id="btnSegundaVia" translate="@APP-PAINEL-INICIAL-2-VIA-DE-CONTA">...</button> is not clickable at point (848, 552). Other element would receive the click: <div uib-modal-window="modal-window" class="modal fade ng-scope ng-isolate-scope" role="dialog" aria-labelledby="modal-title" aria-describedby="modal-body" index="0" animate="animate" ng-style="{'z-index': 1050 + $$topModalIndex*10, display: 'block'}" tabindex="-1" uib-modal-animation-class="fade" modal-in-class="in" modal-animation="true" style="z-index: 1050; display: block;">...</div>
  (Session info: chrome=70.0.3538.67)
  (Driver info: chromedriver=2.42.591088 (7b2b2dca23cca0862f674758c9a3933e685c27d5),platform=Windows NT 10.0.17134 x86_64)
  • I believe it is enough to put the exception after the except. In this case the exception would be selenium.common.exceptions.WebDriverException

1 answer

2

So - the exceptions we put in charge except has to be the Python classes that declare exceptions, not just their names, not just strings.

In case, the error tells you which file it is declared in:

Selenium.common.exceptions.Webdriverexception

That is, you should be able to import it in the Python file where you will put Try...except with an import like this at the beginning of the file:

from selenium.common.exceptions import WebDriverException

And then, further down the file, where you have the except can directly use the name WebDriverException

try:
   # seu código aqui
   ...
except WebDriverException as erro:
   print("Erro - exceção Webdriverexception: ", erro, file=sys.stderr)
...

(The print inside of except is just an example, it can be any code of yours to deal with the error).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.