Working around Selenium

After you’ve used selenium for a while, you’ll be familiar with some of the problems.

Yep, WaitForElement doesn’t exactly cover itself in glory. It is possible to work round this a bit using a static helper for retries. Something like this;

    public static void MyNavigateMethod(this IWebDriver driver, int retryCounter = 0)

            // select the "Return to third party checkbox
        catch (Exception ex)
            if (retryCounter <= 5)
                // retry this again
                Trace.WriteLine(string.Format(" - exception occurred: '{1}', retrying: {0}", retryCounter, ex.GetType().ToString()));
                Thread.Sleep(retryCounter * retrySleep);
                driver.MyNavigateMethod(retryCounter: retryCounter);

Here we have passed an optional retryCounter into the method, and then within the exception iterated this counter and get the method to call itself.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

A Website.

Up ↑

%d bloggers like this: