Through javascript running within the context of a page (and limited by the browser sandbox) it is not possible to manipulate documents from another domain, either in a new window or in an iframe. This is for security reasons.
If you want a visual answer to this: see the browser window opening and the commands being executed (maybe to pass the control to the user after it reaches some given state, such as after clicking search), it basically has two solutions:
An extension to the browser:
Extensions can inject code into a specific page (like inserting an extra button on the google page), or add a direct button on the browser bar, or shortcut keys. Any of these can be trigger to start action: manipulating the DOM of the page.
The downside is that you will have to do an extension for each browser you want to support, possibly using completely different APIs.
Automation Library:
Use an external program that will launch a new browser process and will "control" it. This is supported by all major browsers and is relatively simple to program. Two good libraries: Selenium and < strong> Watir .
Finally, you may not want a visible browser or iteration with the user. Want to do everything dark and just get the result later (an array of search results titles, for example). For this you need a headless browser.
PhantomJS :
As already mentioned in other answers. It is an interface to WebKit, but without creating a window or visual of any kind. You're in control of everything.
Deploy your HTTP Client:
Here you can use any language you want. Simply open a TCP socket and communicate with the site server using the HTTP protocol. The big problem here is that the page javascript will not run and will have to render the HTML manually, you will be very limited. On the other hand it is the fastest and most efficient way to get data. You can make a single request for http://www.google.com/search?q=teste
for example.