Put except with error name in python

-1

I need to create a try except with two exceptions, but I do not know how to put the specific error in the first except, the error that appears below, could someone 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)
    
asked by anonymous 05.11.2018 / 20:40

1 answer

1

Then - the exceptions we put in the except command must be the classes in Python that declare the exceptions, not only their names, not just strings.

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

selenium.common.exceptions.WebDriverException

That is, you should be able to import it into 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

Then, further down the file, where you have except you 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 the except is just an example, it can be any code of yours to handle the error).

    
07.11.2018 / 03:06