开发者

Problem in starting selenium

I'm getting issue in starting selenium. Actually my thread class has selenium.start() in run() method. So when I'm using below lines of code,

//some another class
class someclass{

    ScrapeThread nidleThread = new ScrapeThread("nidleThread");    
    Thread scraper = new Thread(niidleThread);
    scraper.start()
}

as thread.start() method internally calls run() method, so in run() method of thread class only first two three lines of code are getting executed and when it executes comes to selenium.start() and executes, then selenium is giving issue in starting means I can see only two commands getting executed in command history of selenium remote and then getting struck there.

But when i m using below code and directly calling the run() method of my thread class

//some another class
class someclass{
    ScrapeThread nidleThread = new ScrapeThread("nidleThread");    
    nidleThread.run();
}

here it's working properly and I'm getting proper output as I want.

What could be the issue in starting selenium when I'm executing the thread in normal way i.e. by calling scra开发者_C百科pper.start() method?

//in thread class
run(){   
    selenium = new DefaultSelenium(config.getHost(), Integer.parseInt(config.getPort()),          config.getBrowser(), config.getUrl());            
    selenium.start();                                                        
}         

The code in run() method of thread class

public void run() {

    try {

        System.out.println("in the run method");

        scraper = siteToScrape.getSiteScraper();

        scraper.setStartPageType(pageTypeToScrape);

        scraper.setPageTypeToScrape(typeToScrape);

        SocialParser parser = siteToScrape.getSiteParser();
        selenium = new DefaultSelenium(config.getHost(), Integer.parseInt(config.getPort()), config.getBrowser(), config.getUrl());
        selenium.start();
        System.out.println("EXECUTED 1!!");//after this nothing is getting                
                                                       //executed
        Integer count = 0;
        System.out.println("EXECUTED 2!!");
        while (startUrl != null) {
        System.out.println("EXECUTED 3!!");
            HtmlPage homePage = new HtmlPage();
            homePage.setCreatedBy(new String());
            homePage.setCreatedon(new String());
            homePage.setModifiedBy(new String());
            homePage.setModifiedOn(new String());
            homePage.setNoOfItemsFound(new String());
            homePage.setOwnedBy(urlOwnedBy);
            homePage.setPageType(scraper.getPageTypeToScrape());
            homePage.setPageUrl(startUrl);
            element  = getInitialisedElement();
            scraper.setNavigator(element.getNavigator());
            scraper.setStartUrl(startUrl);
            try {
                scraper.initialize();//some more stuff
            }catch (Exception e) {
        e.printStackTrace();
    }


Well, I'm assuming what you're trying to do is create a thread to perform some page-scraping using selenium to drive the browser? If so, I'd make sure that your selenium server config is correct and then also I'd make sure that the selenium.start() isn't being called concurrently with anything trying to invoke any selenium commands.

From my experience, you should be very careful when dealing with multiple threads as if I were to do something like this:


Thread threadOne = new Thread(something);
Thread threadTwo = new Thread(somethingElse);

threadOne.start(); threadTwo.start();

This does not necessarily mean that threadOne will start before nor exactly concurrently with threadTwo.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜