Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium Firefox Open timeout

Using Windows 2008, C#, Firefox 3.5.1, Selenium RC (v1.0.1)

When it works, this code executes very quickly and the page loads within .5 seconds.

However, the session always seems to fail after 3 - 5 iterations. The open command will cause a window to be spawned, but no page to be loaded. Eventually a timeout exception is returned. The page has not actually timed out. Instead, it is as though the request for a URL has never reached the browser window.

class Program
    {
        static void Main(string[] args)
        {
            for (int i = 0; i < 10; i++)
            {
                var s = new DefaultSelenium("localhost", 4444, "firefox", "http://my.server");
                s.Start();
                s.SetSpeed("300");
                s.Open("/");
                s.WaitForPageToLoad("30000");
                s.Type("//input[contains(@id, '_username')]", "my.test");
                s.Type("//input[contains(@id, '_password')]", "password");
                s.Stop();

            }
        }
    }
like image 517
goofballLogic Avatar asked Jun 28 '10 17:06

goofballLogic


2 Answers

I have a similar set up (Firefox 3.6.15, Selenium RC 1.0.1, but on WinXP and using the Python libraries) and I am working with a couple of sites - one site is naturally prone to timeouts in normal use (e.g. by a human user) whereas the others typically are not. Those that aren't appear a little slower but the one that is prone to timeouts is significantly slower when run via RC than by a person - it won't always timeout but the incidence is much much more common.

My limited mental model for this is that somehow the extra steps RC is doing (communicating with the browser, checking what it sees in the returned pages etc etc) are somehow adding a bit to each step of the page loads and then at some point they will push it over the edge. Obviously this is overly simplified, I just haven't had time to properly investigate.

Also, I do tend to notice that the problem gets worse over time, which fits a little with what the OP has seen (i.e. working the first time but not after 3 - 5 attempts). Often a reboot seems to fix the issues, but without proper investigation I can't tell why this helps, perhaps it is somehow freeing up memory (the machine is used for other things), getting allocated to a different one of our company's proxies or something else I haven't considered.

So... not much of a full answer here (a comment would have been more appropriate, but my login isn't able to yet), but at least it reinforces that you're not the only one. Periodic restarts are an annoying thing to need to do, but in the absence of any smarter analysis and answers, maybe they'd be worth a shot?

like image 166
Neil Avatar answered Sep 24 '22 05:09

Neil


I was facing the same problem .This is because open method of DefaultSelenium has timeout of 30000ms, so it waits for 30s for your page to load. You can try this trivial solution.

//selenium is DefaultSelenium instance as private member of the class

            boolean serverStartTry = false;
        int tryCount =1;

        while((!serverStartTry) && tryCount <= Constants.maxServerTries){
            try{
                this.selenium.open(ReadConFile.readcoFile("pageName"));
                System.out.println("Server started in try no: "+tryCount);
                serverStartTry =true;
            }catch (SeleniumException e) {
                System.out.println("Server start try no: "+tryCount );
                System.out.println("Server Start Try: "+ serverStartTry);
                serverStartTry = false;
                tryCount++;
            }
        }
        if(!serverStartTry){
            System.out.println("Server Not started, no. of attempts made: "+tryCount);
            System.exit(0);
        }
like image 42
9ikhan Avatar answered Sep 22 '22 05:09

9ikhan