caoheike
caoheike
2017-05-17 02:50

htmlunit 如何监听来自页面的alert 请说的详细些

3
  • 控制台
  • html5

package com.hommsun.util;

import java.io.IOException;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.springframework.util.Assert;

import com.gargoylesoftware.htmlunit.AlertHandler;
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;

public class weizai implements AlertHandler {
public static void main(String[] args) throws FailingHttpStatusCodeException, MalformedURLException, IOException {
WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER);
webClient.getCookieManager().setCookiesEnabled(true);// 开启cookie管理
webClient.getOptions().setTimeout(90000);
webClient.getOptions().setCssEnabled(true);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.setJavaScriptTimeout(40000);
webClient.getOptions().setRedirectEnabled(true);
webClient.getOptions().setThrowExceptionOnScriptError(false);

    HtmlPage page= webClient.getPage("http://192.168.1.108/");

}

@Override
public void handleAlert(Page arg0, String arg1) {

}

}

以上的连接是我些的测试页面 会直接弹出 alert 控制台也会输出

10:35:52.651 [main] WARN com.gargoylesoftware.htmlunit.javascript.host.Window - window.alert("asdsa") no alert handler installed

我想拿到提示 然后 给页面显示

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答

为你推荐

换一换