[prev in list] [next in list] [prev in thread] [next in thread] 

List:       htmlunit-user
Subject:    Re: [Htmlunit-user] Website giving error "JavaScript or Cookies not supported"
From:       "Nitin Tomer" <ntomer () newgen ! co ! in>
Date:       2013-09-03 6:59:58
Message-ID: 007801cea873$cc515230$64f3f690$ () co ! in
[Download RAW message or body]

Hi Marc,

I made the following changes in the program - 

		webClient = new WebClient(BrowserVersion.FIREFOX_17);
		webClient.setThrowExceptionOnScriptError(false);

		HashMap <String,String> mapOfPages = new
HashMap<String,String>();
		log.log("Before calling getPage for www.manta.com");
		HtmlPage page1 =
webClient.getPage("http://www.manta.com/mb#Location");

		// New addition starts
		Thread.sleep(4000);
		Page1 = (HtmlPage)webClient.get
CurrentWindow().getEncodedPage();

		int tries = 0;
		while(page1.asXml().contains("please activate JavaScript")
> > page1.asXml().contains("activate your browser cookies"))
		{
			log.log("Wrong page, trying again");
			
			if(tries < 100)
			{
				page1 =
webClient.getPage("http://www.manta.com/mb#Location");
			}
			else
			{
				log.log("100 tries over");
				break;
			}
			tries++;
		}

Even now I do not get the correct page at first try, but once it goes inside
the while loop, it tries only once and I get the correct page. What might be
happening here?

Regards

Nitin

-----Original Message-----
From: Marc Guillemot [mailto:mguillemot@yahoo.fr] 
Sent: Tuesday, September 03, 2013 11:26 AM
To: htmlunit-user@lists.sourceforge.net
Subject: Re: [Htmlunit-user] Website giving error "JavaScript or Cookies not
supported"

Hi,

comments inline.

> I am trying to access a page using HtmlUnit, but it's returning me an
> page saying JavaScript and Cookies aren't enabled. But it opens alright
> from the browser. Here is the source code for it -
> 
> webClient = new WebClient(BrowserVersion.FIREFOX_17);
> 
> CookieManager cookieManager = new CookieManager();
> cookieManager.clearCookies();
> cookieManager.setCookiesEnabled(true);
> webClient.setCookieManager(cookieManager);
> webClient.getOptions().setJavaScriptEnabled(true);
> webClient.setJavaScriptTimeout(0);
> webClient.getOptions().setTimeout(0);

these 7 lines could be removed: these are already the default settings.

> webClient.setThrowExceptionOnScriptError(false);
> 
> HashMap <String,String> mapOfPages = new HashMap
> <String,String>();
> log.log("Before calling getPage for www.manta.com");
> HtmlPage page1 =
> webClient.getPage("http://www.manta.com/mb#Location");
> 
> int tries = 0;
> while(page1.asXml().contains("please activate JavaScript") ||
> page1.asXml().contains("activate your browser
cookies"))

are you sure that this is the right test? Many sites have this text in 
the page without to display it if JS is enabled / cookies are supported.

> {
> log.log("Wrong page, trying again");
> 
> if(tries < 100)
> {
> page1 =
> webClient.getPage("http://www.manta.com/mb#Location");
> }
> else
> {
> log.log("100 tries over");
> break;
> }
> tries++;
> }
> 
> Please tell me what I am doing wrong?
> 
> Regards
> 
> Nitin

Cheers,
Marc.
-- 
HtmlUnit support & consulting from the source
Blog: http://mguillem.wordpress.com


----------------------------------------------------------------------------
--
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
Htmlunit-user mailing list
Htmlunit-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/htmlunit-user

Disclaimer :- This e-mail and any attachment may contain confidential, proprietary or \
legally privileged information. If you are not the original intended recipient and \
have erroneously received this message, you are prohibited from using, copying, \
altering or disclosing the content of this message. Please delete it immediately and \
notify the sender. Newgen Software Technologies Ltd (NSTL)  accepts no \
responsibilities for loss or damage arising from the use of the information \
transmitted by this email including damages from virus and further acknowledges that \
no binding nature of the message shall be implied or assumed unless the sender does \
so expressly with due authority of NSTL.


------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
Htmlunit-user mailing list
Htmlunit-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/htmlunit-user


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic