3

I am trying to open a website and grab some data using Selenium with PhantomJS, however it takes a lot of time to open a website (about 30 second). And every time I open other link I have to wait 30+Seconds. What is wrong with my code ?

        static void Main(string[] args)
        {
        IWebDriver browser = new PhantomJSDriver();

        var URL = "http://www.cbssports.com/nba/playerrankings ";

        browser.Navigate().GoToUrl(URL);

        //Position
        var title = browser.FindElements(By.CssSelector(".tableTitle"));
        Console.WriteLine(title.First().Text);

        Console.Read();
        }

Things I have tried to do:
1.Set PhantomJS proxy type to none
2.Disable internet option: automatically detect settings
3.Disable IPv6 protocol

PhantomJS release notes claim, that there are some known issues with network performance on Microsoft Windows. According to release notes, solution is to set proxy type to none, however that doesn't work.

Community
  • 1
  • 1
Jonas
  • 43
  • 7

2 Answers2

2

You have to wait 30 seconds because you haven't defined timeouts which are 30 seconds as default. You should use this predefined driver service.

        var phantomJSDriverService = PhantomJSDriverService.CreateDefaultService();
        IWebDriver browser = new PhantomJSDriver(phantomJSDriverService);
        browser.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(0));
Evaldas B
  • 2,464
  • 3
  • 17
  • 25
1

The default timeout for Selenium is 30 seconds. You are using browser.FindElements() (the plural version), which will wait the full 30 seconds before continuing!

You can reduce the timeout with browser.manage().timeouts().implicitlyWait(), or you can use explicit timeouts.

SiKing
  • 10,003
  • 10
  • 39
  • 90