HTMLunit - Facebook Login

final WebClient webClient = new WebClient();
    webClient.setJavaScriptEngine(new JavaScriptEngine(webClient));
    HtmlPage page1 = null;
    try {
        page1 = webClient.getPage("http://www.facebook.com");
    } catch (IOException e) {
        e.printStackTrace();
    }
    final HtmlForm form = (HtmlForm) page1.getElementById("login_form");

    final HtmlSubmitInput button = (HtmlSubmitInput) form.getInputsByValue("Log In").get(0);
    final HtmlTextInput textField = (HtmlTextInput) page1.getElementById("email");
    textField.setValueAttribute("test@test.com");
    final HtmlPasswordInput textField2 = (HtmlPasswordInput) page1.getElementById("pass");
    textField2.setValueAttribute("password1");
    try {
        HtmlPage page2 = button.click();
        System.out.println(page2.getTitleText());

    } catch (IOException e) {
        e.printStackTrace();
    }

I am trying to use HTMLUnit to login to my facebook account. However, I get this error:

I am looking to create a program that automates some of the things that I do with my pages that I have on facebook. I know that something like this probably already exists, but I do it for fun.

======= EXCEPTION START ========


EcmaError: lineNumber=[97] column=[0] lineSource=[<no source>] name=[TypeError] sourceName=[https://fbstatic-a.akamaihd.net/rsrc.php/v2/y8/r/ElsISGBmlSN.js] message=[TypeError: Cannot find function addImport in object [object CSSStyleSheet]. (https://fbstatic-a.akamaihd.net/rsrc.php/v2/y8/r/ElsISGBmlSN.js#97)]
com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot find function addImport in object [object CSSStyleSheet]. (https://fbstatic-a.akamaihd.net/rsrc.php/v2/y8/r/ElsISGBmlSN.js#97)
+3
source share
1 answer

I stopped this error when I added the BrowserVersion constructor to the WebClient constructor:

 final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_38);
+3
source

Source: https://habr.com/ru/post/1786883/


All Articles