java htmlunit failing to load Javascript - java

What is causing this error, and how do I fix it?
WebClient webClient = new WebClient();
HtmlPage page = webClient.getPage("http://stackoverflow.com");
Error message
May 25, 2013 10:34:12 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
May 25, 2013 10:34:13 AM com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter runtimeError
SEVERE: runtimeError: message=[The data necessary to complete this operation is not yet available.] sourceName=[http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js] line=[2] lineSource=[null] lineOffset=[0]
May 25, 2013 10:34:15 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
May 25, 2013 10:34:16 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error
WARNING: CSS error: 'cdn.sstatic.net/stackoverflow/all.css?v=1748204ca390' [1:3230] Error in style rule. (Invalid token "!". Was expecting one of: , , , "inherit", , , , , , , , , , , , , , , , , , , , , , , , , , "}", ";", "/", "-".)
May 25, 2013 10:34:16 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler warning
WARNING: CSS warning: 'cdn.sstatic.net/stackoverflow/all.css?v=1748204ca390' [1:3230] Ignoring the following declarations in this rule.
May 25, 2013 10:34:16 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error
WARNING: CSS error: 'cdn.sstatic.net/stackoverflow/all.css?v=1748204ca390' [1:6341] Error in style rule. (Invalid token "!". Was expecting one of: , , , "inherit", , , , , , , , , , , , , , , , , , , , , , , , , , "}", ";", "/", "-".)
May 25, 2013 10:34:16 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler warning
WARNING: CSS warning: 'cdn.sstatic.net/stackoverflow/all.css?v=1748204ca390' [1:6341] Ignoring the following declarations in this rule.
May 25, 2013 10:34:16 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error
WARNING: CSS error: 'cdn.sstatic.net/stackoverflow/all.css?v=1748204ca390' [1:14777] Error in style rule. (Invalid token "!". Was expecting one of: , , , "inherit", , , , , , , , , , , , , , , , , , , , , , , , , , "}", ";", "/", "-".)
May 25, 2013 10:34:16 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler warning
WARNING: CSS warning: 'cdn.sstatic.net/stackoverflow/all.css?v=1748204ca390' [1:14777] Ignoring the following declarations in this rule.
May 25, 2013 10:34:17 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error
WARNING: CSS error: 'cdn.sstatic.net/stackoverflow/all.css?v=1748204ca390' [1:31657] Error in style rule. (Invalid token "!". Was expecting one of: , , , "inherit", , , , , , , , , , , , , , , , , , , , , , , , , , "}", ";", "/", "-".)
May 25, 2013 10:34:17 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler warning
WARNING: CSS warning: 'cdn.sstatic.net/stackoverflow/all.css?v=1748204ca390' [1:31657] Ignoring the following declarations in this rule.
May 25, 2013 10:34:17 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error
WARNING: CSS error: 'cdn.sstatic.net/stackoverflow/all.css?v=1748204ca390' [1:73253] Error in style rule. (Invalid token ":". Was expecting one of: , , , "inherit", , , , , , , , , , , , , , , , , , , , , , , , , , "}", ";", "/", "-".)
May 25, 2013 10:34:17 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler warning
WARNING: CSS warning: 'cdn.sstatic.net/stackoverflow/all.css?v=1748204ca390' [1:73253] Ignoring the following declarations in this rule.
May 25, 2013 10:34:17 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error
WARNING: CSS error: 'cdn.sstatic.net/stackoverflow/all.css?v=1748204ca390' [1:112886] Error in expression. (Invalid token "#ffffff". Was expecting one of: , , , , , , , "-", "=", ")".)
May 25, 2013 10:34:17 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error
WARNING: CSS error: 'cdn.sstatic.net/stackoverflow/all.css?v=1748204ca390' [1:112928] Error in style rule. (Invalid token "background". Was expecting one of: , "}", ";".)
May 25, 2013 10:34:17 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler warning
WARNING: CSS warning: 'cdn.sstatic.net/stackoverflow/all.css?v=1748204ca390' [1:112928] Ignoring the following declarations in this rule.
May 25, 2013 10:34:19 AM com.gargoylesoftware.htmlunit.javascript.host.ActiveXObject jsConstructor
WARNING: Automation server can't create object for 'ShockwaveFlash.ShockwaveFlash.7'.
May 25, 2013 10:34:19 AM com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter runtimeError
SEVERE: runtimeError: message=[Automation server can't create object for 'ShockwaveFlash.ShockwaveFlash.7'.] sourceName=[http://www.google-analytics.com/ga.js] line=[25] lineSource=[null] lineOffset=[0]
May 25, 2013 10:34:19 AM com.gargoylesoftware.htmlunit.javascript.host.ActiveXObject jsConstructor
WARNING: Automation server can't create object for 'ShockwaveFlash.ShockwaveFlash.6'.
May 25, 2013 10:34:19 AM com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter runtimeError
SEVERE: runtimeError: message=[Automation server can't create object for 'ShockwaveFlash.ShockwaveFlash.6'.] sourceName=[http://www.google-analytics.com/ga.js] line=[25] lineSource=[null] lineOffset=[0]
May 25, 2013 10:34:19 AM com.gargoylesoftware.htmlunit.javascript.host.ActiveXObject jsConstructor
WARNING: Automation server can't create object for 'ShockwaveFlash.ShockwaveFlash'.
May 25, 2013 10:34:19 AM com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter runtimeError
SEVERE: runtimeError: message=[Automation server can't create object for 'ShockwaveFlash.ShockwaveFlash'.] sourceName=[http://www.google-analytics.com/ga.js] line=[25] lineSource=[null] lineOffset=[0]
May 25, 2013 10:34:20 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'application/x-javascript'.
May 25, 2013 10:34:21 AM org.apache.http.client.protocol.ResponseProcessCookies processCookies
WARNING: Invalid cookie header: "Set-Cookie: azk-views=; Max-Age=31536000000; Path=/; Expires=Sun, 25 May 2014 17:34:42 GMT". Invalid max-age attribute: 31536000000
May 25, 2013 10:34:21 AM org.apache.http.client.protocol.ResponseProcessCookies processCookies
WARNING: Invalid cookie header: "Set-Cookie: azk-events=; Max-Age=2592000000; Path=/; Expires=Mon, 24 Jun 2013 17:34:42 GMT". Invalid max-age attribute: 2592000000
May 25, 2013 10:34:21 AM org.apache.http.client.protocol.ResponseProcessCookies processCookies
WARNING: Invalid cookie header: "Set-Cookie: azk-voting=; Max-Age=2592000000; Path=/; Expires=Mon, 24 Jun 2013 17:34:42 GMT". Invalid max-age attribute: 2592000000
May 25, 2013 10:34:21 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
May 25, 2013 10:34:23 AM com.gargoylesoftware.htmlunit.javascript.background.JavaScriptJobManagerImpl runSingleJob
SEVERE: Job run failed with unexpected RuntimeException: Exception invoking setInnerHTML

Those are not errors, they are warnings.
They are caused by HtmlUnit's JavaScript engine Mozilla’s Rhino being unable to properly interpret some JavaScript code. (It is not as "good" as some other popular JS Engines.)
You can turn those warnings off, here's how:
public static void main(String[] args) throws Exception {
// turn off htmlunit warnings
java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(java.util.logging.Level.OFF);
java.util.logging.Logger.getLogger("org.apache.http").setLevel(java.util.logging.Level.OFF);
WebClient webClient = new WebClient();
HtmlPage page = webClient.getPage("http://stackoverflow.com");
System.out.println(page.getTitleText());
}
Output:
Stack Overflow

Set enable Javascript and CSS in the webClient browser as:
webClient.getOptions().setJavaScriptEnabled(false);
webClient.getOptions().setCssEnabled(false);
You can ON / OFF by passint true or false parameters.

Related

How to suppress htmlunit (Java library) warning/error messages?

I'm using htmlunit [http://htmlunit.sourceforge.net/] and it spews out a bunch of warnings/error:
Mar 24, 2017 6:37:30 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
Mar 24, 2017 6:37:31 PM com.gargoylesoftware.htmlunit.html.InputElementFactory createElementNS
INFO: Bad input type: "datetime", creating a text input
Mar 24, 2017 6:37:31 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'application/x-javascript'.
Mar 24, 2017 6:37:32 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'application/x-javascript'.
Mar 24, 2017 6:37:34 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
Mar 24, 2017 6:37:34 PM com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter runtimeError
SEVERE: runtimeError: message=[An invalid or illegal selector was specified (selector: '*,:x' error: Invalid selector: :x).] sourceName=[https://www.example.com/bundles/jquery?v=u8J3xxyrazUhSJl-OWRJ6I82HpC6Fs7PQ0-l8XzoZXY1] line=[1] lineSource=[null] lineOffset=[0]
Mar 24, 2017 6:37:35 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
Mar 24, 2017 6:37:35 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
Mar 24, 2017 6:37:35 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
Mar 24, 2017 6:37:36 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
Mar 24, 2017 6:37:43 PM com.gargoylesoftware.htmlunit.javascript.host.dom.Document createElement
INFO: createElement: Provided string 'iframe name="rufous-frame-29_-1">https://platform.twitter.com/widgets.js] line=[9] lineSource=[null] lineOffset=[0]
I've looked at other resources and tried to turn it off by:
Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(Level.OFF);
Logger.getLogger("org.apache.http").setLevel(Level.OFF);
and:
final WebClient webClient = new WebClient(BrowserVersion.EDGE);
but it does not work.
What else can be done to suppress these warning/error messages?
If you are not going set the loggers to OFF in 'logging.properties' file then you need pin the loggers with a hard reference before you set the level to OFF.
Here is a corrected example based off your code:
private static final Logger[] PINNED_LOGGERS;
static {
System.setProperty("org.apache.commons.logging.simplelog.defaultlog", "fatal");
PINNED_LOGGERS = new Logger[]{
Logger.getLogger("com.gargoylesoftware.htmlunit"),
Logger.getLogger("org.apache.http")
};
for (Logger l : PINNED_LOGGERS) {
l.setLevel(Level.OFF);
}
}
I put the following at the start of the application and the errors/warnings stopped:
System.getProperties().put("org.apache.commons.logging.simplelog.defaultlog", "fatal");
Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(Level.OFF);
Logger.getLogger("org.apache.http").setLevel(Level.OFF);

Getting Error while creating EventHubClient in Microsoft Azure

I am using the latest 0.8.2 jar for java eventhub library and I have used the following code to send the data to azure eventhub :
ConnectionStringBuilder connStr = new ConnectionStringBuilder(connectionstring);
byte[] payloadBytes = valueChangeMessage.data.get().toString().getBytes("UTF-8");
EventData sendEvent = new EventData(payloadBytes);
EventHubClient ehClient = EventHubClient.createFromConnectionStringSync(connStr.toString());
ehClient.sendSync(sendEvent);
But I am getting the following error:
Sep 15, 2016 3:31:25 PM org.apache.qpid.proton.engine.impl.ssl.SslEngineFacadeFactory getClass
WARNING: unable to load org.bouncycastle.openssl.PEMReader
Sep 15, 2016 3:31:25 PM org.apache.qpid.proton.engine.impl.ssl.SslEngineFacadeFactory <clinit>
WARNING: unable to load bouncycastle provider
Sep 15, 2016 3:31:26 PM com.microsoft.azure.servicebus.MessagingFactory$RunReactor run
WARNING: UnHandled exception while processing events in reactor:
java.lang.IllegalArgumentException
org.apache.qpid.proton.engine.impl.EventImpl.dispatch(EventImpl.java:112)
org.apache.qpid.proton.reactor.impl.ReactorImpl.dispatch(ReactorImpl.java:309)
org.apache.qpid.proton.reactor.impl.ReactorImpl.process(ReactorImpl.java:277)
com.microsoft.azure.servicebus.MessagingFactory$RunReactor.run(MessagingFactory.java:332)
java.lang.Thread.run(Thread.java:745)Cause: null
java.nio.Buffer.position(Buffer.java:244)
org.apache.qpid.proton.engine.impl.ssl.SimpleSslTransportWrapper.pop(SimpleSslTransportWrapper.java:411)
org.apache.qpid.proton.engine.impl.ssl.SslImpl$UnsecureClientAwareTransportWrapper.pop(SslImpl.java:185)
org.apache.qpid.proton.engine.impl.TransportImpl.pop(TransportImpl.java:1476)
org.apache.qpid.proton.reactor.impl.SelectorImpl.select(SelectorImpl.java:145)
org.apache.qpid.proton.reactor.impl.IOHandler.handleQuiesced(IOHandler.java:57)
org.apache.qpid.proton.reactor.impl.IOHandler.onUnhandled(IOHandler.java:381)
org.apache.qpid.proton.engine.BaseHandler.onReactorQuiesced(BaseHandler.java:87)
org.apache.qpid.proton.engine.BaseHandler.handle(BaseHandler.java:206)
org.apache.qpid.proton.engine.impl.EventImpl.dispatch(EventImpl.java:108)
org.apache.qpid.proton.reactor.impl.ReactorImpl.dispatch(ReactorImpl.java:309)
org.apache.qpid.proton.reactor.impl.ReactorImpl.process(ReactorImpl.java:277)
com.microsoft.azure.servicebus.MessagingFactory$RunReactor.run(MessagingFactory.java:332)
java.lang.Thread.run(Thread.java:745)
Sep 15, 2016 3:31:26 PM com.cognizant.iotworkbench.Channel.CatChannel sendPOST
SEVERE: null
com.microsoft.azure.servicebus.ServiceBusException: java.lang.IllegalArgumentException, TrackingId: a9055d98-2dff-4cc0-af1f-38a9718b3cf5, at: 2016-09-15T15:31:26.462+05:30[Asia/Calcutta]
at com.microsoft.azure.servicebus.MessagingFactory$RunReactor.run(MessagingFactory.java:357)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalArgumentException
at java.nio.Buffer.position(Buffer.java:244)
at org.apache.qpid.proton.engine.impl.ssl.SimpleSslTransportWrapper.pop(SimpleSslTransportWrapper.java:411)
at org.apache.qpid.proton.engine.impl.ssl.SslImpl$UnsecureClientAwareTransportWrapper.pop(SslImpl.java:185)
at org.apache.qpid.proton.engine.impl.TransportImpl.pop(TransportImpl.java:1476)
at org.apache.qpid.proton.reactor.impl.SelectorImpl.select(SelectorImpl.java:145)
at org.apache.qpid.proton.reactor.impl.IOHandler.handleQuiesced(IOHandler.java:57)
at org.apache.qpid.proton.reactor.impl.IOHandler.onUnhandled(IOHandler.java:381)
at org.apache.qpid.proton.engine.BaseHandler.onReactorQuiesced(BaseHandler.java:87)
at org.apache.qpid.proton.engine.BaseHandler.handle(BaseHandler.java:206)
at org.apache.qpid.proton.engine.impl.EventImpl.dispatch(EventImpl.java:108)
at org.apache.qpid.proton.reactor.impl.ReactorImpl.dispatch(ReactorImpl.java:309)
at org.apache.qpid.proton.reactor.impl.ReactorImpl.process(ReactorImpl.java:277)
at com.microsoft.azure.servicebus.MessagingFactory$RunReactor.run(MessagingFactory.java:332)
... 1 more
Can anyone help me with finding the possible issue for this?

Errors running HtmlUnit with Java

Attempting to use HtmlUnit. I want to input a username(pin) and password(password) and get to the next page. The output is a long list of errors.
I am unable to post all the errors. However, the majority are duplicates. I've posted below each unique error message I've received:
Sep 10, 2015 7:00:35 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'application/x-javascript'.
Sep 10, 2015 7:00:41 PM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error
WARNING: CSS error: 'https://app.applyyourself.com/common/stylesheet.css' [141:2] Error in style rule. (Invalid token ".2". Was expecting one of: <S>, <LBRACE>, ".", ":", "[", <COMMA>, <HASH>, <S>.)
Sep 10, 2015 7:00:44 PM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error
WARNING: CSS error: 'https://app.applyyourself.com/common/bootstrap.css' [2590:17] Error in expression; ':' found after identifier "progid".
Sep 10, 2015 7:00:45 PM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error
WARNING: CSS error: 'https://app.applyyourself.com/common/style.css' [130:25] Error in expression; ':' found after identifier "data".
Sep 10, 2015 7:00:45 PM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error
WARNING: CSS error: 'https://app.applyyourself.com/common/style.css' [131:8] Error in declaration. (Invalid token ",". Was expecting one of: <S>, ":".)
Sep 10, 2015 7:00:45 PM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error
WARNING: CSS error: 'https://app.applyyourself.com/common/style.css' [142:17] Invalid color "#7d7e7d\0".
Sep 10, 2015 7:00:45 PM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error
WARNING: CSS error: 'https://app.applyyourself.com/common/style.css' [166:23] Invalid color "#cccccc\0".
Sep 10, 2015 7:00:45 PM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error
WARNING: CSS error: 'https://app.applyyourself.com/common/style.css' [459:17] Invalid color "#b5b5b5\0".
Sep 10, 2015 7:00:45 PM com.gargoylesoftware.htmlunit.html.InputElementFactory createElementNS
INFO: Bad input type: "tel", creating a text input
Sep 10, 2015 7:00:45 PM com.gargoylesoftware.htmlunit.html.InputElementFactory createElementNS
INFO: Bad input type: "url", creating a text input
Sep 10, 2015 7:00:45 PM com.gargoylesoftware.htmlunit.html.InputElementFactory createElementNS
INFO: Bad input type: "email", creating a text input
Sep 10, 2015 7:00:45 PM com.gargoylesoftware.htmlunit.html.InputElementFactory createElementNS
INFO: Bad input type: "datetime", creating a text input
Sep 10, 2015 7:00:47 PM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error
WARNING: CSS error: 'https://app.applyyourself.com/AYApplicantLogin/fl_ApplicantLogin.asp?id=dukegrad' [1:141] Error in declaration. '*' is not allowed as first char of a property.
I've tried using these links:
How to use HtmlUnit in Java?
Groovy htmlunit getFirstByXPath returning null + OCR Question
Here is the code:
public ApplicationLogin(String pin, String password) throws Exception {
WebClient webClient = new WebClient();
HtmlPage webPage = webClient.getPage("https://app.applyyourself.com/AYApplicantLogin/fl_ApplicantLogin.asp?id=dukegrad");
HtmlForm form = webPage.getFirstByXPath("//form[#id='frmApplicantLogin']");
HtmlTextInput username = form.getInputByName("UserID");
HtmlPasswordInput pass = form.getInputByName("Password");
HtmlSubmitInput b = form.getInputByValue("login");
username.setValueAttribute(pin);
pass.setValueAttribute(password);
HtmlPage webPage2 = b.click();
}
Use another WEB driver instead of default. For instance it could be CHROME (you can chose between different browsers like CHROME, FIREFOX_31, FIREFOX_31, INTERNET_EXPLORER_8, INTERNET_EXPLORER_11 ).
WebClient webClient = new WebClient(BrowserVersion.CHROME);
I suppose it should fix your problem.

Expected content type of 'application/javascript' in HtmlUnitDriver

i'm trying to execute javascript but couldn't find any way to do so ..
i have to mention that i've tried my code with FirefoxDriver and it's work great and do exactly what i want but the problem with FirefoxDriver is that the browser actually work and visible to user which i don't want . that's why i've switch to HtmlUnitdriver
--here's my code--
HtmlUnitDriver driver = new HtmlUnitDriver(true);
driver.get("https://blahblah.edu/home.faces");
WebElement select = driver.findElement(By.name("loginForm:userType"));
Select tbs = new Select(select);
tbs.selectByValue("1");
driver.findElement(By.name("loginForm:username")).sendKeys("username");
driver.findElement(By.name("loginForm:password")).sendKeys("password");
driver.executeScript("javascript:userTypeSelect();");//throws exception
driver.executeScript("if(typeof jsfcljs == 'function'){jsfcljs(document.getElementById('menuForm'),{'menuForm:serLinkDropAdd2':'menuForm:serLinkDropAdd2'},'');}return false");
WebDriverWait driverWait = new WebDriverWait(driver, 10000);
driverWait.until(ExpectedConditions.presenceOfElementLocated(By.id("saveBut1")));
driver.findElement(By.id("saveBut1")).click();
System.out.println(driver.getTitle());
--here's the Error--
Aug 30, 2013 2:44:04 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Expected content type of 'application/javascript' or 'application/ecmascript' for remotely loaded JavaScript element at 'https://edugate.blahblah.edu/ksu/include/js/calendar/deleteTooltip.js', but got 'text/plain'.
Aug 30, 2013 2:44:05 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Expected content type of 'application/javascript' or 'application/ecmascript' for remotely loaded JavaScript element at 'https://edugate.blahblah.edu/ksu/include/js/calendar/deleteNote.js', but got 'text/plain'.
Aug 30, 2013 2:44:05 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Expected content type of 'application/javascript' or 'application/ecmascript' for remotely loaded JavaScript element at 'https://edugate.blahblah.edu/ksu/include/js/menu/styleswitcher.js', but got 'text/plain'.
Aug 30, 2013 2:44:07 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error
WARNING: CSS error: 'https://edugate.blahblah.edu/ksu/include/css/style_ar.css' [8:9] Error in pseudo class or element. (Invalid token ":". Was expecting one of: <IDENT>, <FUNCTION_NOT>, <FUNCTION_LANG>, <FUNCTION>.)
Aug 30, 2013 2:44:07 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler warning
WARNING: CSS warning: 'https://edugate.blahblah.edu/ksu/include/css/style_ar.css' [8:9] Ignoring the whole rule.
Aug 30, 2013 2:44:08 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error
WARNING: CSS error: 'https://edugate.blahblah.edu/ksu/skins/1/style_ar.css' [8:9] Error in pseudo class or element. (Invalid token ":". Was expecting one of: <IDENT>, <FUNCTION_NOT>, <FUNCTION_LANG>, <FUNCTION>.)
Aug 30, 2013 2:44:08 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler warning
WARNING: CSS warning: 'https://edugate.blahblah.edu/ksu/skins/1/style_ar.css' [8:9] Ignoring the whole rule.
Aug 30, 2013 2:44:11 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Expected content type of 'application/javascript' or 'application/ecmascript' for remotely loaded JavaScript element at 'https://edugate.blahblah.edu:443/ksu/include/js/table/table.js', but got 'text/plain'.
Exception in thread "main" org.openqa.selenium.WebDriverException: com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot set property [Window].length that has only a getter to 15. (https://edugate.blahblah.edu:443/ksu/include/js/table/table.js#2)
Build info: version: '2.35.0', revision: '8df0c6b', time: '2013-08-12 15:43:19'
System info: os.name: 'Windows 8', os.arch: 'amd64', os.version: '6.2', java.version: '1.7.0_21'
Driver info: driver.version: HtmlUnitDriver
at org.openqa.selenium.htmlunit.HtmlUnitDriver.executeScript(HtmlUnitDriver.java:497)
at edugate.ADD2.<init>(ADD2.java:32)
at edugate.Edugate.main(Edugate.java:31)
Caused by: com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot set property [Window].length that has only a getter to 15. (https://edugate.blahblah.edu:443/ksu/include/js/table/table.js#2)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:669)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:601)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:507)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:601)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:576)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:1005)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.executeScript(HtmlUnitDriver.java:491)
... 2 more
Caused by: com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot set property [Window].length that has only a getter to 15. (https://edugate.blahblah.edu:443/ksu/include/js/table/table.js#2)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:669)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:601)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:507)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:555)
at com.gargoylesoftware.htmlunit.html.HtmlPage.loadExternalJavaScriptFile(HtmlPage.java:1082)
at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:399)
at com.gargoylesoftware.htmlunit.html.HtmlScript$3.execute(HtmlScript.java:260)
at com.gargoylesoftware.htmlunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:276)
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:676)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:635)
at org.cyberneko.html.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1169)
at org.cyberneko.html.HTMLTagBalancer.endElement(HTMLTagBalancer.java:1071)
at org.cyberneko.html.filters.DefaultFilter.endElement(DefaultFilter.java:206)
at org.cyberneko.html.filters.NamespaceBinder.endElement(NamespaceBinder.java:330)
at org.cyberneko.html.HTMLScanner$ContentScanner.scanEndElement(HTMLScanner.java:3074)
at org.cyberneko.html.HTMLScanner$ContentScanner.scan(HTMLScanner.java:2041)
at org.cyberneko.html.HTMLScanner.scanDocument(HTMLScanner.java:918)
at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:499)
at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:452)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.parse(HTMLParser.java:892)
at com.gargoylesoftware.htmlunit.html.HTMLParser.parse(HTMLParser.java:241)
at com.gargoylesoftware.htmlunit.html.HTMLParser.parseHtml(HTMLParser.java:187)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:268)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:156)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:434)
at com.gargoylesoftware.htmlunit.WebClient.loadDownloadedResponses(WebClient.java:2289)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.doProcessPostponedActions(JavaScriptEngine.java:697)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.access$500(JavaScriptEngine.java:91)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:664)
... 8 more
Caused by: net.sourceforge.htmlunit.corejs.javascript.EcmaError: TypeError: Cannot set property [Window].length that has only a getter to 15. (https://edugate.blahblah.edu:443/ksu/include/js/table/table.js#2)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3603)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3587)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3608)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError3(ScriptRuntime.java:3630)
at com.gargoylesoftware.htmlunit.javascript.SimpleScriptable.isReadOnlySettable(SimpleScriptable.java:461)
at net.sourceforge.htmlunit.corejs.javascript.ScriptableObject$GetterSlot.setValue(ScriptableObject.java:259)
at net.sourceforge.htmlunit.corejs.javascript.ScriptableObject.putImpl(ScriptableObject.java:2796)
at net.sourceforge.htmlunit.corejs.javascript.ScriptableObject.put(ScriptableObject.java:521)
at net.sourceforge.htmlunit.corejs.javascript.ScriptableObject.putProperty(ScriptableObject.java:2479)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.setName(ScriptRuntime.java:1846)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1207)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:798)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:105)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:405)
at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:275)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3031)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.exec(InterpretedFunction.java:115)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$3.doRun(JavaScriptEngine.java:546)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:654)
... 38 more
Java Result: 1
i appreciate your help , thanks in advance
webClient java script disable will help, add a code line
webClient.setJavaScriptEnabled(false);
before your get request.
MSR

Login Using HtmlUnit

I am very very new to HtmlUnit. I want to know do I am able to login to a site using htmlunit and perform some operations in the site for example I want to login to my office portal and to aplly a leave.I am using html unit and it shows some errors, is its possible to do with html unit or are there any other tools I can use for this purpose... Here is my code
final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3_6);
webClient.setJavaScriptEnabled(true);
webClient.getCookieManager().setCookiesEnabled(true);
final HtmlPage page1 = webClient.getPage("http://www.ccstechnologies.org/login.aspx/");
final HtmlForm form = page1.getFormByName("form1");
final HtmlSubmitInput button = form.getInputByName("BtnLogin");
final HtmlTextInput textField = form.getInputByName("Username");
final HtmlPasswordInput pwd = form.getInputByName("password");
textField.setValueAttribute("username");
pwd.setValueAttribute("password");
final HtmlPage page2 = button.getEnclosingForm().click();
String htmlBody = page2.getWebResponse().getContentAsString();
System.out.println("Base Uri 1 : "+page1);
System.out.println("Base Uri 2 : "+page2);
webClient.closeAllWindows();
But when I print page2 it shows only the login page's url, and it is not returning the homepage url. What could be the problem ?
This is what I got in my console when clicked on form
May 28, 2012 11:44:15 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered:'application/x-javascript'.
May 28, 2012 11:44:16 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'application/x-javascript'.
Base Uri 1 : HtmlPage(http://www.ccstechnologies.org/login.aspx/)#2741851
Base Uri 2 : HtmlPage(http://www.ccstechnologies.org/login.aspx/)#2741851
results generated when clicked on button
May 29, 2012 10:00:02 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'application/x-javascript'.
May 29, 2012 10:00:02 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'application/x-javascript'.
May 29, 2012 10:00:03 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'application/x-javascript'.
May 29, 2012 10:00:03 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'application/x-javascript'.
May 29, 2012 10:00:03 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'application/x-javascript'.
May 29, 2012 10:00:03 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'application/x-javascript'.
May 29, 2012 10:00:03 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
May 29, 2012 10:00:03 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
May 29, 2012 10:00:03 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
May 29, 2012 10:00:03 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
May 29, 2012 10:00:03 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
May 29, 2012 10:00:03 AM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'text/javascript'.
May 29, 2012 10:00:03 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error
WARNING: CSS error: [259:24] Error in expression. Invalid token "=". Was expecting one of: <S>, <COMMA>, "/", <PLUS>, "-", <HASH>, <STRING>, ")", <URI>, "inherit", <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <DIMENSION>, <PERCENTAGE>, <NUMBER>, <FUNCTION>, <IDENT>.
May 29, 2012 10:00:03 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error
WARNING: CSS error: [259:29] Error in style rule. Invalid token "\r\n ". Was expecting one of: "}", ";".
May 29, 2012 10:00:03 AM com.gargoylesoftware.htmlunit.DefaultCssErrorHandler warning
WARNING: CSS warning: [259:29] Ignoring the following declarations in this rule.
HtmlPage(http://192.168.0.5/login.aspx)#23511316
HtmlPage(http://192.168.0.5/login.aspx)#17700115
Ok, I looked into it, it would seem the problem was with the button. I replaced you line of code for the button with this:
final HtmlPage page2 = (HtmlPage) form.getInputByValue("Login").click();
now it appears that it at least tries to login(and the page of course prints invalid login) so it should work with appropriate credentials.
to print the page in java and see it use system.out.println(page1.asText()) or asXml depending on what you want to see
my code is finally this:
final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3_6);
webClient.setJavaScriptEnabled(true);
webClient.getCookieManager().setCookiesEnabled(true);
try{ final HtmlPage page1 = webClient.getPage("http://www.ccstechnologies.org/login.aspx/");
final HtmlForm form = page1.getFormByName("form1");
final HtmlSubmitInput button = form.getInputByName("BtnLogin");
final HtmlTextInput textField = form.getInputByName("Username");
final HtmlPasswordInput pwd = form.getInputByName("password");
textField.setValueAttribute("username");
pwd.setValueAttribute("password");
System.out.println(page1.asText());
final HtmlPage page2 = (HtmlPage) form.getInputByValue("Login").click();
String htmlBody = page2.getWebResponse().getContentAsString();
System.out.println(page2.asText());
System.out.println("Base Uri 1 : "+page1);
System.out.println("Base Uri 2 : "+page2);
webClient.closeAllWindows();}catch (Exception e) {
// TODO: handle exception
}
this is what you should set for the javascript:
webClient.getOptions().setJavaScriptEnabled(false);
and you can as well add these to it.
webClient.getOptions().setRedirectEnabled(true);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setUseInsecureSSL(true);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
webClient.getCookieManager().setCookiesEnabled(true);
This should solve the problem as it did for me.
try to set cookies enabled, and try to set javascript enabled
ignore errors that it might print...(I used to think errors in red are bad, in html unit it seems not necessarily)
If the website uses an ajax call to login.
This worked for me. Set this
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
This would cause all ajax calls to be synchronous.
This is how I setup my WebClient object
WebClient webClient = new WebClient(BrowserVersion.CHROME);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setUseInsecureSSL(true);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
webClient.getCookieManager().setCookiesEnabled(true);
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getCookieManager().setCookiesEnabled(true);

Categories

Resources