Not being able to catch an exception

yayu

So I am trying to catch the Webdriver exception and don't want its traceback to pollute my logs. Here is the bit of code

from selenium.common.exceptions import TimeoutException, WebDriverException

try:
    WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.CSS_SELECTOR, '.loading')))
except TimeoutException:
    log.msg("Seneium Timeout: {}".format(response.url))
except WebDriverException as e:
    log.msg("Selenium Exception: {0} Message: {1}".format("my message", str(e)))
finally:
    driver.quit()

yet I'm still getting these:

 <full traceback here>
 selenium.common.exceptions.WebDriverException: Message: Can not connect to GhostDriver

What am I doing wrong?

alecxe

The exception is raised outside of your try/except block while initializing a WebDriver instance:

driver = webdriver.PhantomJS()

FYI, this happens while starting PhantomJS with GhostDriver, quote from the source code:

def start(self):
    """
    Starts PhantomJS with GhostDriver.

    :Exceptions:
     - WebDriverException : Raised either when it can't start the service
       or when it can't connect to the service
    """
    try:
        self.process = subprocess.Popen(self.service_args, stdin=subprocess.PIPE,
                                        close_fds=platform.system() != 'Windows',
                                        stdout=self._log, stderr=self._log)

    except Exception as e:
        raise WebDriverException("Unable to start phantomjs with ghostdriver.", e)
    count = 0
    while not utils.is_connectable(self.port):
        count += 1
        time.sleep(1)
        if count == 30:
             raise WebDriverException("Can not connect to GhostDriver")

And, start() is called in WebDriver's constructor (__init__() method).

In other words, it starts a service, but cannot connect to it.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Not being able to catch an exception

From Dev

Exception not being caught at catch site

From Dev

Not being able to catch POST variable in a PHP

From Dev

How to catch an exception generated in a Thread to be able to manipulate it

From Dev

Not able to catch c# web api exception

From Dev

Exception isn't being picked up in catch

From Dev

Exception isn't being picked up in catch

From Dev

Sql Exception Not Being Passed to C# Catch

From Dev

Not being able to stop at exception when using consecutive stream.flatMap

From Dev

KMODE_EXCEPTION_NOT_HANDLED, and Windows not being able to fix disk errors

From Dev

Will throwing an exception in a catch block lead to two exceptions being in flight?

From Dev

Not being able to autowire a bean

From Dev

Not being able to use promise

From Dev

Try catch not being forced

From Dev

Java catch being ignored

From Dev

Jquery Not being able to disable event

From Dev

Not being able to call the right data

From Dev

Jquery Not being able to disable event

From Dev

Not being able to set a value to a combobox

From Dev

Difference between Catch(Exception) and Catch(Exception ex)

From Dev

I have a pdf from which I have to extract data and show but I am getting this exception, I'm not being able to figure out what is this Exception is?

From Dev

Catch the same exception twice

From Java

Catch multiple Exception with Lenses

From Dev

Catch cin exception

From Dev

Unable to catch exception NoSuchElementException

From Dev

Continually catch exception in python

From Dev

Catch OptimizeWarning as an exception

From Dev

Catch duplicate entry Exception

From Dev

How to catch this SignalR exception

Related Related

HotTag

Archive