0

I have a problem that my phantomjs loads one site too slow, always at least 60 seconds though on other sites like google.com it takes less than 1 second.

PhantomJSDriverService service = PhantomJSDriverService.CreateDefaultService();
service.IgnoreSslErrors = true;
service.LoadImages = false;
service.ProxyType = "none";
service.HideCommandPromptWindow = true;

using (IWebDriver driver = new PhantomJSDriver(service ))
{
    driver.Navigate().GoToUrl("http://abc.xyz");  //blocks too long
    ...
}

Is there any way to force it finish loading after reaching some point so the script will continue?

JeffC
  • 22,180
  • 5
  • 32
  • 55
nam vo
  • 3,271
  • 12
  • 49
  • 76
  • When you browse to that one site manually, is it just as slow? Maybe it's just the site and not the script. – JeffC Sep 15 '15 at 04:09
  • thanks for your reply. The site has DomContentLoaded: 5.7s, and finish is around 60s as above. That's why I think if there's a way to only load some parts like reaching my target table id="abc" , the rest is not important. It seems no way to do that as the driver will block and wait till finishing the page load. – nam vo Sep 15 '15 at 04:22

2 Answers2

2

I see what you are asking now. You have a long loading page that you want to stop after the relevant stuff loads. I run into this same issue with some of the sites that we have at work but I have not tried a programmatic solution. Sorry, I don't know phantomjs but I found some links that I think would be helpful.

The way I would approach it is to wait for the DOMContentLoaded event to fire and then send an ESC to the page. At least that's what I do manually to stop the long loading files that I don't care about so that the execution can continue.

I found this question How can I wait for the page to be ready in PhantomJS? Here's the relevant part:

var page = require('webpage').create();
var system = require('system');

page.onInitialized = function() {
    page.onCallback = function(data) {
        console.log('Main page is loaded and ready');
        //Do whatever here
    };

    page.evaluate(function() {
        document.addEventListener('DOMContentLoaded', function() {
            window.callPhantom();
        }, false);
        console.log("Added listener to wait for page ready");
    });
};

page.open('https://www.google.com', function(status) {});

Once you detect DOMContentLoaded, use sendkeys() to send the ESC key. I honestly don't know if this will work but it's where I would start. Hopefully it will get you started.

Community
  • 1
  • 1
JeffC
  • 22,180
  • 5
  • 32
  • 55
0

I've just found out the reasons why the phantomjs load so slow because the target web has too many extensions, ads... so I switch to chrome and use adblock like Running Selenium WebDriver using Python with extensions (.crx files)

Community
  • 1
  • 1
nam vo
  • 3,271
  • 12
  • 49
  • 76