0

I am a Newbie with HtmlUnit .. I want to login on https://trash-mail.com/posteingang/ .

My Code:

public static void main(String[] args) throws FailingHttpStatusCodeException, MalformedURLException, IOException {

        WebClient webClient = new WebClient(BrowserVersion.CHROME);

        HtmlPage page1 = webClient.getPage("https://www.trash-mail.com/posteingang/");

        HtmlForm form = page1.getFormByName("inbox-form");

I get the following error:

runtimeError: message=[An invalid or illegal selector was specified (selector: 'select option:selected' error: Invalid selector: select option:selected).] sourceName=[https://www.trash-mail.com/js/jquery-1.9.1.min.js.pagespeed.ce.OXdUuknp4M.js] line=[4] lineSource=[null] lineOffset=[0] Exception in thread "main" com.gargoylesoftware.htmlunit.ElementNotFoundException: elementName=[form] attributeName=[name] attributeValue=[inbox-form] at com.gargoylesoftware.htmlunit.html.HtmlPage.getFormByName(HtmlPage.java:647)

Do u have any Idea how this could gonna work?

Regards, MaddinCoy

It is legal to do this stuff on this site.

MaddinCoy
  • 3
  • 1

1 Answers1

0

On that HTML page, I don't see any form with that name - inbox-form. inbox-form is the id of the form not name.

<form id="inbox-form" action="#" method="post" enctype="multipart/form-data" class="form-horizontal" autocomplete="off">

Either add name attribute to form or use one of getElementById methods.

This page has only one form so you can try this syntax too HtmlForm form = page.getForms().get(0);

EDIT - I tried running your code , issue occurs at HtmlPage page = webClient.getPage("https://www.trash-mail.com/posteingang/");

Error Message - SEVERE: runtimeError: message=[An invalid or illegal selector was specified (selector: 'select option:selected' error: Invalid selector: select option:selected).] sourceName=[https://www.trash-mail.com/js/jquery-1.9.1.min.js.pagespeed.ce.OXdUuknp4M.js] line=[4] lineSource=[null] lineOffset=[0]

That seems like Jquery support issue of HtmlUnit or some bug in that script or usage , htmlUnitbugs

My advice - 1. don't throw exceptions from main method, try to handle those exceptions 2. debug your each line of code

Doesn't seem we can do much since you can't change that page.

Sabir Khan
  • 9,826
  • 7
  • 45
  • 98
  • Thanks for your reply! If i use 'final HtmlForm form = (HtmlForm) page.getElementById("inbox-form");' I get an error... could u please give me a example how to find form and enter something in this form? Thanks... – MaddinCoy Jan 07 '16 at 12:43
  • what error? try your old code by adding name attribute to form first. – Sabir Khan Jan 07 '16 at 14:30
  • ` runtimeError: message=[An invalid or illegal selector was specified (selector: 'select option:selected' error: Invalid selector: select option:selected).] sourceName=[https://www.trash-mail.com/js/jquery-1.9.1.min.js.pagespeed.ce.OXdUuknp4M.js] line=[4] lineSource=[null] lineOffset=[0] ` The Webpage isn't my project cant change code on webserver – MaddinCoy Jan 07 '16 at 14:34
  • I have revised my answer , try another syntax `HtmlForm form = page.getForms().get(0);` – Sabir Khan Jan 08 '16 at 04:44