Selenium href blank New Window test

hrefselenium-rctarget

So, using Selenium, I want to test links on a page and see if they open a new window. They are NOT javascript links, just a basic href "target=_blank".
I want to make sure the newly opened window actually loaded a page.
I can do all the scripting to get the link clicked, but when i test for page Title, I get the page I'm testing on, not the new window that is on top.
How do I target that new window and check to see if THAT page loaded?

thanks

Best Answer

The following worked for me with a form with attribute target="_blank" that sends a POST request on a new window:

// Open the action in a new empty window
selenium.getEval("this.page().findElement(\"//form[@id='myForm']\").target='my_window'");
selenium.getEval("selenium.browserbot.getCurrentWindow().open('', 'my_window')");

//The contents load in the previously opened window
selenium.click("//form[@id='myForm']//input[@value='Submit']");
Thread.sleep(2000);

//Focus in the new window
selenium.selectWindow("my_window");
selenium.windowFocus();
/* .. Do something - i.e.: assertTrue(.........); */

//Close the window and back to the main one
selenium.close();
selenium.selectWindow(null);
selenium.windowFocus();

The html code would be similar to:

<form id="myForm" action="/myAction.do" target="_blank">
    <input type="text" name="myText" value="some text"/>
    <input type="submit" value="Save"/>
</form>