How can I automate certain actions on a certain web page using javascript and jquery? - Stack Overflow

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

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745549872a4632523.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信