找不到 HtmlUnit getform() 表单

HtmlUnit getform() form not found

我是 HtmlUnit 的新手。我想登录 https://trash-mail.com/posteingang/

我的代码:

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");

我收到以下错误:

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)

你知道这是怎么回事吗?

此致, 马丁科伊

在这个网站上做这些事是合法的。

在 HTML 页面上,我没有看到任何具有该名称的表单 - inbox-forminbox-form 是形式的 id 而不是名称。

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

为表单添加 name 属性或使用 getElementById 方法之一。

此页面只有一种形式,因此您也可以尝试使用此语法HtmlForm form = page.getForms().get(0);

编辑 - 我试过 运行 你的代码,问题出现在 HtmlPage page = webClient.getPage("https://www.trash-mail.com/posteingang/");

错误消息 - 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]

这似乎是 Jquery HtmlUnit 的支持问题或该脚本或用法中的一些错误,htmlUnitbugs

我的建议 - 1. 不要从 main 方法中抛出异常,尝试处理这些异常 2. 调试你的每一行代码

我们似乎无能为力,因为您无法更改该页面。