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:
- Navigating to a url
- Logging into the site by typing the password and clicking the login button
- Then click another button, which would open a list of items.
- 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.org/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.