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);
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.
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.
I'm running the following code that errors when I try to commit my changes using Cayenne as my ORM. The code is pasted below and errors out on the context.commitChanges();line. The output messages are pasted below the code. Any help on figuring this out would be appreciated.
import org.apache.cayenne.access.DataContext;
import java.util.*;
import com.jared.*;
public class Main {
public static void main(String[] args) {
DataContext context = DataContext.createDataContext();
Stocks theStock=(Stocks) context.createAndRegisterNewObject(Stocks.class);
theStock.setAsk(3.4);
theStock.setAvgdailyvolume(323849);
theStock .setBid(5.29);
theStock.setChange(-1.22);
theStock.setDayhigh(9.21);
theStock.setDaylow(2.11);
theStock.setLasttradeprice(5.11);
theStock.setLasttradesize(3827);
theStock.setOpen(6.21);
theStock.setPriorclose(4.21);
theStock.setShortratio(1.1);
theStock.setSymbol("^SP%");
theStock.setVolume(28193);
theStock.setLasttradedate(new Date());
context.commitChanges();
System.out.println("Done with the database");
}
}
Nov 20, 2008 11:20:37 PM org.apache.cayenne.conf.RuntimeLoadDelegate startedLoading
INFO: started configuration loading.
Nov 20, 2008 11:20:37 PM org.apache.cayenne.conf.RuntimeLoadDelegate shouldLoadDataDomain
INFO: loaded domain: stocks
Nov 20, 2008 11:20:37 PM org.apache.cayenne.conf.RuntimeLoadDelegate loadDataMap
INFO: loaded .
Nov 20, 2008 11:20:37 PM org.apache.cayenne.conf.RuntimeLoadDelegate shouldLoadDataNode
INFO: loading .
Nov 20, 2008 11:20:37 PM org.apache.cayenne.conf.RuntimeLoadDelegate shouldLoadDataNode
INFO: using factory: org.apache.cayenne.conf.DriverDataSourceFactory
Nov 20, 2008 11:20:37 PM org.apache.cayenne.conf.DriverDataSourceFactory load
INFO: loading driver information from 'stocksNode.driver.xml'.
Nov 20, 2008 11:20:37 PM org.apache.cayenne.conf.DriverDataSourceFactory$DriverHandler init
INFO: loading driver org.hsqldb.jdbcDriver
Nov 20, 2008 11:20:37 PM org.apache.cayenne.conf.DriverDataSourceFactory$LoginHandler init
INFO: loading user name and password.
Nov 20, 2008 11:20:37 PM org.apache.cayenne.access.QueryLogger logPoolCreated
INFO: Created connection pool: jdbc:hsqldb:file:/hsqldb/data/stocks
Driver class: org.hsqldb.jdbcDriver
Min. connections in the pool: 1
Max. connections in the pool: 1
Nov 20, 2008 11:20:37 PM org.apache.cayenne.conf.RuntimeLoadDelegate shouldLoadDataNode
INFO: loaded datasource.
Nov 20, 2008 11:20:37 PM org.apache.cayenne.conf.RuntimeLoadDelegate initAdapter
INFO: no adapter set, using automatic adapter.
Nov 20, 2008 11:20:37 PM org.apache.cayenne.conf.RuntimeLoadDelegate finishedLoading
INFO: finished configuration loading in 203 ms.
Exception in thread "main" org.apache.cayenne.CayenneRuntimeException: [v.3.0M4 May 18 2008 16:32:02] Commit Exception
at org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:1192)
at org.apache.cayenne.access.DataContext.commitChanges(DataContext.java:1066)
at Main.main(Main.java:24)
Caused by: java.lang.NullPointerException
at org.apache.cayenne.access.DataDomainInsertBucket.createPermIds(DataDomainInsertBucket.java:101)
at org.apache.cayenne.access.DataDomainInsertBucket.appendQueriesInternal(DataDomainInsertBucket.java:76)
at org.apache.cayenne.access.DataDomainSyncBucket.appendQueries(DataDomainSyncBucket.java:80)
at org.apache.cayenne.access.DataDomainFlushAction.preprocess(DataDomainFlushAction.java:183)
at org.apache.cayenne.access.DataDomainFlushAction.flush(DataDomainFlushAction.java:135)
at org.apache.cayenne.access.DataDomain.onSyncFlush(DataDomain.java:821)
at org.apache.cayenne.access.DataDomain$2.transform(DataDomain.java:788)
at org.apache.cayenne.access.DataDomain.runInTransaction(DataDomain.java:847)
at org.apache.cayenne.access.DataDomain.onSync(DataDomain.java:785)
at org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:1164)
... 2 more
user name, password?
ClientConnection connection = new
HessianConnection("http://localhost:8080/cayenne-service",
"cayenne-user", "secret",
null);