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:
- 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" ".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:
- 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/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 badges3 Answers
Reset to default 2It 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:
- 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" ".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:
- 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/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 badges3 Answers
Reset to default 2It 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
版权声明:本文标题:How can I automate certain actions on a certain web page using javascript and jquery? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745549871a2155578.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论