java htmlpage_Java:HTML单元点击()

我用Java和HTML单元解析一个网站。这是我想按的按钮

这是我的一部分代码

public void parse_del(String delno){

try

{

WebClient client = new WebClient(BrowserVersion.CHROME);

client.getOptions().setCssEnabled(false);

client.getOptions().setJavaScriptEnabled(false);

//get first page

HtmlPage currentPage = (HtmlPage)client.getPage("https://www.t-cat.com.tw/Inquire/Trace.aspx");

//find inout area

HtmlTextInput inputbox = (HtmlTextInput) currentPage.getElementById("ContentPlaceHolder1_txtQuery1");

//set value

inputbox.setValueAttribute(delno);

//find the send button

HtmlElement send = (HtmlElement) currentPage.getElementById("ContentPlaceHolder1_btnSend");

//click

HtmlPage newpage = send.click();

}

catch (Exception ex){

System.out.println("ERROR !");

}

}

但是点击按钮后它仍然在同一个页面上。我想原因可能是这句台词

client.getOptions().setJavaScriptEnabled(false);

函数click()无法成功执行,因为我启用了javascript。

但是如果我删除这一行,将会有很多警告信息,比如

17, 2019 10:13:34 com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify

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

17, 2019 10:13:34 com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleSheet isValidCondition

Warning: Unhandled CSS condition type 'PREFIX_ATTRIBUTE_CONDITION'. Accepting it silently.

17, 2019 10:13:34 com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter runtimeError

Warning: runtimeError: message=[An invalid or illegal selector was specified (selector: '*,:x' error: Invalid selector: *:x).] sourceName=[https://www.t-cat.com.tw/js/jquery.js] line=[2] lineSource=[null] lineOffset=[0]

17, 2019 10:13:34 com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify

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

17, 2019 10:13:34 com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify

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

17, 2019 10:13:34 com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify

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

整个程序将在开始时存储。

我该怎么做才能解决这个问题?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值