I am doing project in Maven. I try to get pages from URl. Till now I am successful in getting pages from web. But I have two questions,
Qustions,
- Below code takes around 14 seconds to get any two URL pages, how can I reduce this time, Help me in optimizing this.
- After completing the execution, it does not exits from code. Why ?
I ended the code with
driver.close()
. Then, why, it does not exits successfully. I added snapshots before starting and after completing the process. Please see these.
Help me in my problem. Please.
My code:-
package XXX.YYY.ZZZ.Template_Matching;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import java.io.IOException;
import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.w3c.dom.Document;
public class HtmlUnit {
public static void main(String[] args) throws Exception {
String url1 = "http://www.jabong.com/men/shoes/men-loafers/?source=home-leftnav";
String url2 = "http://www.jabong.com/fastrack-9915Pp36J-Black-Pink-Analog-Watch-198499.html";
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "C://Users//jhamb//Desktop//phantomjs-1.9.0-windows//phantomjs.exe");
WebDriver driver = new PhantomJSDriver(caps);
driver.get(url1);
String hml1 = driver.getPageSource();
driver.get(url2);
String hml2 = driver.getPageSource();
driver.close();
//System.out.println(hml1);
//System.out.println(hml2);
Document doc1 = Jsoup.parse(hml1);
Document doc2 = Jsoup.parse(hml2);
// Some operations using these DOM tree, just like , comparing Templates of two URLS
}
}
Snapshot before starting the process,
Snapshot after completing the process, when it waits for no reason,