htmlunit : An invalid or illegal selector was specified

无人久伴 提交于 2019-12-07 18:16:40

问题


I am trying to simulate the login with htmlunit. Although I wrote my code according to the examples, I have encountered a boring problem. Below are some message I have picked up from the console.

runtimeError: message=[An invalid or illegal selector was specified (selector: '*,:x'         error: Invalid selector: *:x).] sourceName=[http://user.mofangge.com/Scripts/inc/jquery-1.10.2.js] line=[1640] lineSource=[null] lineOffset=[0]

WARNING: Obsolete content type encountered: 'application/x-javascript'.

CSS error: 'http://user.mofangge.com/Content/Css/Style1/Main.css' [1:1] Error in style sheet. (Invalid token "\u9518". Was expecting one of: <EOF>, <S>, <IDENT>, "<!--", "-->", <HASH>, <IMPORT_SYM>, <PAGE_SYM>, <MEDIA_SYM>, <FONT_FACE_SYM>, <CHARSET_SYM>, ".", ":", "*", "[", <ATKEYWORD>.)

Aug 11, 2014 1:43:27 下午 com.gargoylesoftware.htmlunit.DefaultCssErrorHandler error

CSS error: 'http://user.mofangge.com/Content/Css/Style1/Login.css' [1:1] Error in style sheet. (Invalid token "\u9518". Was expecting one of: <EOF>, <S>, <IDENT>, "<!--", "-->", <HASH>, <IMPORT_SYM>, <PAGE_SYM>, <MEDIA_SYM>, <FONT_FACE_SYM>, <CHARSET_SYM>, ".", ":", "*", "[", <ATKEYWORD>.)

runtimeError: message=[An invalid or illegal selector was specified (selector: ':input' error: Invalid selector: *:input).] sourceName=[http://user.mofangge.com/Scripts/inc/jquery-1.10.2.js] line=[1275] lineSource=[null] lineOffset=[0]

Here is my code. And I got nothing useful. I don't know why that happened and wish for any help.

    WebClient webClient = new WebClient(BrowserVersion.CHROME);     
    webClient.getOptions().setCssEnabled(true);
    webClient.getOptions().setJavaScriptEnabled(true);
    webClient.getOptions().setThrowExceptionOnScriptError(false);
    webClient.getOptions().setTimeout(10000);

    DefaultCredentialsProvider credentialsProvider = (DefaultCredentialsProvider)webClient.getCredentialsProvider(); 
    credentialsProvider.addCredentials("username", "password"); 


    HtmlPage page = webClient.getPage(url); 
    HtmlForm loginForm = page.getFormByName("regform");         


    HtmlInput username = loginForm.getInputByName("txt_userid"); 
    HtmlInput password = loginForm.getInputByName("txt_userpw"); 

    username.setValueAttribute("username"); 
    password.setValueAttribute("password");         


    HtmlSubmitInput submit = page.getHtmlElementById("login_btn");

    webClient.waitForBackgroundJavaScript(30000);
    HtmlPage result = submit.click();


    FileWriter writer = new FileWriter("mofang.html"); 
    writer.write(result.getWebResponse().getContentAsString()); 
    writer.close(); 

回答1:


Put

webClient.waitForBackgroundJavaScript(30000);

after

HtmlPage result = submit.click()


来源:https://stackoverflow.com/questions/25236619/htmlunit-an-invalid-or-illegal-selector-was-specified

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!