admin管理员组

文章数量:1022594

I am learning javascript and would like to exercise a simple task, which I just fail to get right.

All I want is to automate these actions:

  1. Navigating to a url
  2. Logging into the site by typing the password and clicking the login button
  3. Then click another button, which would open a list of items.
  4. Enumerate the list of items, expanding each item by clicking a certain link.

This should be basic for any experienced javascript/jquery programmer, but I am kind of lost.

Here is what I have until now: html:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ".dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Bump the site</title>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="bump.js"></script>
</head>
<body>
</body>
</html>

bump.js:

jQuery(function($) {
  var intervalID = null;

  function checkPasswordField() {
    $("#password").val("my-password");
    if ($("#password").val() === "my-password") {
      clearInterval(intervalID);
      $("#login")[0].click();
    }
  }

  window.location.href = "";
  $(document).ready(function() {
    intervalID = window.setInterval(checkPasswordField, 1000);
  });
});

Of course, it does not work. When the site is loaded, the bump.js script is no longer with us - Chrome does not show it in the list of the loaded scripts. I guess, this behavior is logical, but then how do I do it?

Thanks.

I am learning javascript and would like to exercise a simple task, which I just fail to get right.

All I want is to automate these actions:

  1. Navigating to a url
  2. Logging into the site by typing the password and clicking the login button
  3. Then click another button, which would open a list of items.
  4. Enumerate the list of items, expanding each item by clicking a certain link.

This should be basic for any experienced javascript/jquery programmer, but I am kind of lost.

Here is what I have until now: html:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Bump the site</title>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="bump.js"></script>
</head>
<body>
</body>
</html>

bump.js:

jQuery(function($) {
  var intervalID = null;

  function checkPasswordField() {
    $("#password").val("my-password");
    if ($("#password").val() === "my-password") {
      clearInterval(intervalID);
      $("#login")[0].click();
    }
  }

  window.location.href = "http://www.the-site.co.il";
  $(document).ready(function() {
    intervalID = window.setInterval(checkPasswordField, 1000);
  });
});

Of course, it does not work. When the site is loaded, the bump.js script is no longer with us - Chrome does not show it in the list of the loaded scripts. I guess, this behavior is logical, but then how do I do it?

Thanks.

Share Improve this question asked Feb 26, 2012 at 16:01 markmark 63k96 gold badges347 silver badges671 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

It won't work with JavaScript the "normal" way. But you could create a Google Chrome extension to automate the tasks with JavaScript. You can find more information about extensions for Google Chrome here.

I'm not sure this is possible using JQuery, unless the files are available to each page you load which seems is not the case.

Option 1. You could try using an iframe and doing all steps inside that window, this way you would always have the js library available.

Option 2. You could use testing tools such as Selenium to automate some tasks http://seleniumhq/

Hope it helps

This is not something you can do with JavaScript / Jquery. As you noticed, your script is no longer present once you've redirected. This is a good thing, otherwise websites would be vulnerable to scripts from people with much more malicious intent than you. Like injecting scripts into your bank's website to capture your password keystrokes as you type.

I am learning javascript and would like to exercise a simple task, which I just fail to get right.

All I want is to automate these actions:

  1. Navigating to a url
  2. Logging into the site by typing the password and clicking the login button
  3. Then click another button, which would open a list of items.
  4. Enumerate the list of items, expanding each item by clicking a certain link.

This should be basic for any experienced javascript/jquery programmer, but I am kind of lost.

Here is what I have until now: html:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ".dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Bump the site</title>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="bump.js"></script>
</head>
<body>
</body>
</html>

bump.js:

jQuery(function($) {
  var intervalID = null;

  function checkPasswordField() {
    $("#password").val("my-password");
    if ($("#password").val() === "my-password") {
      clearInterval(intervalID);
      $("#login")[0].click();
    }
  }

  window.location.href = "";
  $(document).ready(function() {
    intervalID = window.setInterval(checkPasswordField, 1000);
  });
});

Of course, it does not work. When the site is loaded, the bump.js script is no longer with us - Chrome does not show it in the list of the loaded scripts. I guess, this behavior is logical, but then how do I do it?

Thanks.

I am learning javascript and would like to exercise a simple task, which I just fail to get right.

All I want is to automate these actions:

  1. Navigating to a url
  2. Logging into the site by typing the password and clicking the login button
  3. Then click another button, which would open a list of items.
  4. Enumerate the list of items, expanding each item by clicking a certain link.

This should be basic for any experienced javascript/jquery programmer, but I am kind of lost.

Here is what I have until now: html:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Bump the site</title>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="bump.js"></script>
</head>
<body>
</body>
</html>

bump.js:

jQuery(function($) {
  var intervalID = null;

  function checkPasswordField() {
    $("#password").val("my-password");
    if ($("#password").val() === "my-password") {
      clearInterval(intervalID);
      $("#login")[0].click();
    }
  }

  window.location.href = "http://www.the-site.co.il";
  $(document).ready(function() {
    intervalID = window.setInterval(checkPasswordField, 1000);
  });
});

Of course, it does not work. When the site is loaded, the bump.js script is no longer with us - Chrome does not show it in the list of the loaded scripts. I guess, this behavior is logical, but then how do I do it?

Thanks.

Share Improve this question asked Feb 26, 2012 at 16:01 markmark 63k96 gold badges347 silver badges671 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

It won't work with JavaScript the "normal" way. But you could create a Google Chrome extension to automate the tasks with JavaScript. You can find more information about extensions for Google Chrome here.

I'm not sure this is possible using JQuery, unless the files are available to each page you load which seems is not the case.

Option 1. You could try using an iframe and doing all steps inside that window, this way you would always have the js library available.

Option 2. You could use testing tools such as Selenium to automate some tasks http://seleniumhq/

Hope it helps

This is not something you can do with JavaScript / Jquery. As you noticed, your script is no longer present once you've redirected. This is a good thing, otherwise websites would be vulnerable to scripts from people with much more malicious intent than you. Like injecting scripts into your bank's website to capture your password keystrokes as you type.

本文标签: How can I automate certain actions on a certain web page using javascript and jqueryStack Overflow