Write to external webpage using javascript - javascript

I have a website written in html and javascript/jquery. How can I follow a link to another page(outside my origin--> lets pretend google.com) and automatically enter data into a form and submit it on the outside page?
For example, I want to follow a link on my page to google.com and then have the browser enter info into the search box and make a search.
Selenium?

It's impossible unless the page you are working with has set up GET or POST options that allow you to do such things. There may be other methods, but the page you are working with must first set it up and allow it.
For example, you can run a Google search by appending a q parameter to the URL like so. You can do this because Google uses GET parameters which are easy to determine.
https://www.google.com/q=stackoverflow#safe=off&q=stackoverflow

Related

is there a way to retrieve information from a webpage and use that info to prefill another page?

I'd like to create a browser extension or a javascript to retrieve pieces of information from a currently open webpage and use that info to prefill a form on another webpage.
So, for example, if I'm on a StackOverflow page, I'd like a script that takes info from that page (title, question,...) and prefill that data in a new webpage (eg: https://stackoverflow.com/questions/ask).
I'm not an expert in coding, but I created some scripts using Python and Selenium (nothing too fancy though). I looked for a similar question, but I didn't find anything. Does anyone have an idea on how I could accomplish something like that?
You can do it with the help of content script. fetch the required data from any webpage using a content script and store the data on extension storage. Then you can inject the data to required input on required webpage with executeScript()
for more reference: https://developer.chrome.com/extensions/content_scripts

How to parse webpage response in android?

How do you make it so that if a website has a form let's say, and I want to pass a string into the input tag , press a button, and get the link that's generated in the other page? All of that meaning it should be done in the background, with javascript or somehow. The website in particular is http://www.listentoyoutube.com/ , I want to get the generated audio file link.
I think it's not possible, you should look for another site that supports APIs to do such requests.

Automating Add to Cart Javascript Sequence without browser open with Python

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.

Auto form filling using java script

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

Cross site scripting forms

I want to help fill forms for my users with default values on other pages.
To do that I would like to show another page (from different domain) in an iframe and insert there default values when needed into fields.
But it is not possible because of cross site scripting protection.
I have checked http://sourceforge.net/projects/poxy/ and it almost works to view page through proxy but unfortunately not always. Is there another way to do that? Ie.
How to connect to fields in the iframe? Is it possible?
AFAIK, You cannot access fields from another page like iframe. If you want to fill form by using JS, you can try to write Bookmarklet for your browser. That's a bookmark which executes javascript on current page.

Categories