How do I launch a Jquery event on an HTML website using Java and Eclipse?

Dmitry Kustarnikov :

I am trying to simulate a button click on my school portal's login page. However, when I look into code, I see only name and ID and then an "event" button. The "event" button shows a redirection to the jquery file that redirects the user to a specfic link. I attached some parts of a code.

How can I launch that event inside my code to simulate the button click and get automatically redirected.

P.S. I would be constantly checking for responses, so if there is not enough information, please tell me, so I can create a better question.

[This is a picture of a Login button code:

<input id="LoginButton" style="visibility: visible" type="button" value="Log In">event

I need these actions to be performed directly from my application. (This is located in the index.php folder

function gotologinreminder() {
    top.location = '/novi/StudentPortal/Home/LoginReminder';
};
$("#LoginButton").click(function () {
    $("#msgdisplay").hide();
    $("#imgwait").show();
    if ($("#Pin").val() == "" || $("#Password").val() == "") {
        $("#imgwait").hide();
        $("#msg1").show();
        return;
    };
    $("#loginform").submit();
});
$("#loginform").ajaxForm(function (retval) {
    if (retval.valid == "0") {
        $("#imgwait").hide();
        $("#msgmessage").html(retval.msg);
        $("#msgdisplay").show();
        $("#Pin").val("");
        $("#Password").val("");
        $("#Pin").focus();
    } else {
        $(window).off('resize.rightcolumn');
        top.location = '/novi/StudentPortal/Home/PortalMainPage';
    };
});
function clearmessages() {
    $("#msgdisplay").hide();
    $("#msg1").hide();
};

Thank you,

Dmitry

Jacob S.P. :

If I understood correctly, you want to login through Java code to a website, which has code written in JavaScript. In this case, it would be better to have a look to the network requests that occur as you make the login in the Network tab in the developer console. Specially have a look at those requests made with a POST method, for this means your browser is sending info to the website. I also suggest using the Jsoup library, because it facilitates this type of requests.

Edit 1: I have made an album of screen captures to help you understand. The last image is of the code you would put in a Java Class to make the same login. (I blurred out some info but you will understand)

After getting the document you can then scrape the site using Jsoup as well, here is the documentation.

Note: What the JS code you have shows is nothing more than a validation and the corresponding changes in the UI of the website, for example, checking if either the user or password are empty and then showing an error on the website. The actual form submit function (retval) is not in the code you show (at least as far as I can tell).

To pass the login cookie with Jsoup you would do this:

 Document profilePicDocument = Jsoup.connect(This is the new URL you want to access)
            .cookies(secondLoginPost.cookies()) //secondLoginPost is the last POST request
            .get();

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=101595&siteId=1