My requirement is to write one script when I run the script it opens the page and fill the fields and automatically take me to next page.
For e.g. Script for www.irctc.co.in. When we login to irctc it ask the user name and password and when click on submit it redirect to next page.
I want to write a script in such a way that I just click on the script it internally does all these things and I could see the next page.
I am unable form where I should start.
I think you are looking for something like Greasemonkey: https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/
Greasemonkey is a Mozilla Firefox extension that allows users to install scripts that make on-the-fly changes to web page content after or before the page is loaded in the browser.
If you use a different browser, then you can refer to: http://en.wikipedia.org/wiki/Greasemonkey#Equivalents_for_other_browsers
Check Watir - Web Application Testing in Ruby. Although it is used for automation, it might solve the purpose here. With Watir, you write scripts in ruby and execute it and then see the magic. More information can be found here
Related
I want to use chrome snippet to run a javascript code to autofill a series of pages.
The problem is after another page was opened, the code seems stopped.
Instead, I need it run continually.
Like this:
//Page 1 form
document.getElementById('page1Radiobutton').click()
//Click Next
document.getElementById('page1Next').click()
//Page 2 form (need run continually after page 1 was submitted, but now stop at here...)
document.getElementById('page2Radiobutton').click()
document.getElementById('page2Next').click()
I would look into browser extensions such as Tampermonkey (for Chrome) or Greasemonkey (for Firefox)
With either of these monkeys, you can create snippets of arbitrary javascript that will run on any page on the internet automatically.
If you are going to create a script that runs on every page, make sure it exits gracefully if it can't find the elements you're looking for. Otherwise you'll end up with javascript errors when you go to other pages.
Your JavaScript can't really run across pages. Once the user navigates to a new page, all JavaScript is thrown out by the browser for security (among other) reasons.
I'm looking for a method to automate an add-to-cart process using Python WITHOUT needing to have a browser window open.
I've tried using modules such as mechanize but it does not have the functionality of directly "clicking" a web element
Currently I've been able to automate this process using Selenium but the process of having to open the browser and load web elements, photos, etc adds up to a lengthy process where time is of the essence.
An example page that I would like to automate is here :
http://store.nike.com/us/en_us/pd/kd-vi-elite-basketball-shoe/pid-972328/pgid-972324?cp=usns_twit_041214_basketball_kdelitehome
Any direction is greatly appreciated.
It seems that in the web page you listed, the "Add to Cart" button is actually a form submit button. What you can do is simulate the submission of the form by doing a POST request, with all the necessary form parameters, which you can get from all the <input> elements on the page.
A possible python implementation may be:
Download the page with urllib2. You will probably have to enable cookies.
Parse the page using BeautifulSoup or similar, and find all the <input> tags and their values.
Construct a new POST request with all these params (while maintaining cookies).
You can use your Browser's Network sniffing capabilities to see an actual request being sent, and try to mimic it using the above tools.
Hope it helps.
I have the next task - I have a page where we have some interaction logic:
After a user clicks a button, my script redirects the user to another site where it must be populate 2 textfields then click button, after redirect to new page it must click on another button.
My project is based on ASP.NET MVC4.
My questions are:
May I do all of this?
If yes, how can I redirect to another page and run my script
P.S.: Second web site isn't my site and everything I know is id of buttons where I need to click.
Elaborating on my comment
You cannot do this in a normal browser. You could write a bookmarklet or two that would navigate and click but there is no script you can write in a web page that will do what you want for security reasons. A long time ago, it was possible in IE to load a banking site into an iFrame and script and monitor user interaction to steal credentials. This has been blocked.
If you save an HTML page with the extension HTA, it can be loaded from harddisk in windows and will have relaxed security so you could load the other site into an iFrame and script the interaction. This is likely not what you want.
The last method is to use for example CURL to get the foreign page, insert stuff and submit the form to the foreign site and return the result. This is not recommended either.
So the question to you is: Why do you need this and are there other ways to do what you want
1) location.href = "http://another.page.com"
2) impossible for security purposes
I'm writing an app which should load a website. After the website is loaded, I have to fire up a 2nd command to the web page, which is kind of Javascript scriptlet.
I did this manually in my browser and in generally it seems to work fine. They way I did it manually was I created two shortcuts in my browser:
the URL to this website (e.g. http://www.example.net/123456-e.aspx)
the shortcut to a Scriptlet which calls a function on this website (e.g. javascript:__doPostBack('Video_Info1$Rating_control1$lnk_star5','')).
I first click the URL shortcut and after its loaded, I fire up the 2nd shortcut.
But how can I do this in a C# application?
But, what I'm trying to do is quite the opposite I think.
I'd like to SEND a _postBack to an existing site.
I'm not writing my own site which contains a postBack control!
Let me explain a little in detail...
the site I'm loading in my app is an existing ASPX site in the web.
In this site, you'll find several _doPostback entries and in a browser, the postBack event (when I hit it manually within a bookmark/shortcut) will be send back and has its desired result (in this case, its assigning "5 stars" to tell everybody, that something is supergood ;-).
So, what I'd like to do is to write my C# App which will send this _postBack command every time I hit the OK button or some other events.
Just as it is with my link above
"javascript:__doPostBack('Video_Info1$Rating_control1$lnk_star5','')"
This is the bookmark I have on my browsers bookmark panel - a shortcut!
.... Just to be honest, its a kind of cheat, which will do an automatic voting on an external site...
My prob is now,... how can I send this _postBack straight to the site, to increase my stars?
I am not sure what exactly you are trying to achieve, The code which you are seeing (_doPastBack(..)) is actually going to invoke a server method (code in your codebehind of that page).
You can create a webpage and have an iframe and load your first page in that.The user will be able to click on any of the button and invoke the corresponding server code if there is one attached.
<html>
<body>
<iframe src="http://www.example.net/123456-e.aspx"></iframe>
</body>
Our site uses Facebook Connect to allow users to post updates to their Facebook. The javascript that allows this has to be loaded directly through Facebook's Feature loader, and we had been loading it on every page where a user might want to connect to Facebook. Unfortunately, because some users have Facebook blocked at their workplace, this is causing our site to hang for those users.
Ideally, what we'd like to do is to load the js through the feature loader only just before it is actually needed. However, we do not know whether the feature will be needed until after the page on which it will be used is already loaded. Specifically, a user will open up a dialog box and check "publish to facebook" before submitting a form by AJAX (but NOT leaving the page). It is at this point that we'd like both to load the Facebook js, and immediately execute the code to bring up their dialog box. Is there a reasonable way to do this?
Essentially what you want to do is load the js on demand after the page has already been loaded. This is certainly doable; there is a decent article that summarizes how you might accomplish it here:
http://ajaxpatterns.org/On-Demand_Javascript
I also like the following little functions from phpjs.org:
http://phpjs.org/functions/require_once:503
http://phpjs.org/functions/include_once:434
http://phpjs.org/functions/include:433