0

I'm making a little script in java to check iPhone IMEI numbers. There is this site from Apple : https://appleonlinefra.mpxltd.co.uk/search.aspx

You have to enter an IMEI number. If this number is OK, it drives you to this page : https://appleonlinefra.mpxltd.co.uk/Inspection.aspx Else, you stay on /search.aspx page I want to open the search page, enter an IMEI, submit, and check if the URL has changed. In my code there is a working IMEI number.

Here is my java code :

HtmlPage page = webClient.getPage("https://appleonlinefra.mpxltd.co.uk/search.aspx");

HtmlTextInput imei_input = (HtmlTextInput)page.getElementById("ctl00_ContentPlaceHolder1_txtIMEIVal");

imei_input.setValueAttribute("012534008614194");

//HtmlAnchor check_imei = page.getAnchorByText("Rechercher");
//Tried with both ways of getting the anchor, none works

HtmlAnchor anchor1 = (HtmlAnchor)page.getElementById("ctl00_ContentPlaceHolder1_imeiValidate");
page = anchor1.click();

System.out.println(page.getUrl());

I can't find out where it comes from, since i often use HTMLUnit for this and i never had this issue. Maybe because of the little loading time after submiting ?

Thank you in advance

saperlipopette
  • 177
  • 1
  • 12

1 Answers1

0

You can do this by using a connection wrapper that HTMLUnit provides

Here is an example

    new WebConnectionWrapper(webClient) {

        public WebResponse getResponse(WebRequest request) throws IOException {
            WebResponse response = super.getResponse(request);
            if (request.getUrl().toExternalForm().contains("Inspection.aspx")) {
                String content = response.getContentAsString("UTF-8");

                WebResponseData data = new WebResponseData(content.getBytes("UTF-8"), response.getStatusCode(),
                        response.getStatusMessage(), response.getResponseHeaders());
                response = new WebResponse(data, request, response.getLoadTime());
            }
            return response;
        }
    };

With the connection wrapper above, you can check for any request and response that is passing through HTMLUnit

Arya
  • 8,473
  • 27
  • 105
  • 175
  • Tried to find documentation about the connection wrapper, hard to me to understand it and also your code. I'm trying to adapt it to my situation, but i can't find out out to do – saperlipopette Sep 09 '16 at 07:57