HtmlUnit mouseOver() method

import com.gargoylesoftware.htmlunit.*;  
import com.gargoylesoftware.htmlunit.html.*;  
import java.io.File;

public class HtmlUnitDemo {

	/**
	 * @param args
	 */
	static final WebClient browser;

    static {
        browser = new WebClient(BrowserVersion.INTERNET_EXPLORER_11);
        browser.getOptions().setJavaScriptEnabled(true);
        browser.getOptions().setRedirectEnabled(true);
        browser.setAjaxController(new NicelyResynchronizingAjaxController());
        browser.getOptions().setThrowExceptionOnFailingStatusCode(false);
    }
    
	public static void main(String[] args) {
		HtmlPage currentPage = null;
        try {
        	currentPage = (HtmlPage) browser.getPage("https://www.amazon.com/ap/signin?_encoding=UTF8&openid.assoc_handle=usflex&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0&openid.pape.max_auth_age=0&openid.return_to=https%3A%2F%2Fwww.amazon.com%2Fgp%2Fyourstore%2Fhome%3Fie%3DUTF8%26ref_%3Dnav_signin");
        	currentPage = (HtmlPage) browser.getPage("http://www.amazon.com/");
        	currentPage.save(new File("C:/Users/saikatd/output/homepage.html"));
        	String xpath = "//span[contains(text(), 'Stay on Amazon.com')]";
        	HtmlElement foundElement = (HtmlElement)currentPage.getFirstByXPath(xpath);
        	if(foundElement != null) {
                currentPage = (HtmlPage) foundElement.click();
            	currentPage.save(new File("C:/Users/saikatd/output/homepage1.html"));
        	}
        	xpath = "//a[contains(text(), 'Try Prime')]";
        	foundElement = (HtmlElement)currentPage.getFirstByXPath(xpath);
        	if(foundElement != null) {
            	currentPage = (HtmlPage) foundElement.mouseOver();
            	currentPage.save(new File("C:/Users/saikatd/output/LogoTryPrime.html"));
        	}
        	
        	xpath = "//a[@id = 'nav-your-prime']";
        	if(foundElement != null) {
            	foundElement = (HtmlElement)currentPage.getFirstByXPath(xpath);
            	currentPage = (HtmlPage) foundElement.mouseOver();
            	currentPage.save(new File("C:/Users/saikatd/output/NavBarTryPrime.html"));
        	}
        	
        	xpath = "//a[contains(text(), 'Your Account')]";
        	foundElement = (HtmlElement)currentPage.getFirstByXPath(xpath);
        	if(foundElement != null) {
            	currentPage = (HtmlPage) foundElement.mouseOver();
            	currentPage.save(new File("C:/Users/saikatd/output/YourAccount.html"));
        	}
        	
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Advertisements
This entry was posted in Information Technology. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s