Selenium href blank New window test

So, using Selenium, I want to check the links on the page and see if they open a new window. They are not javascript links, but just the base href "target = _blank". I want to make sure that a recently opened window really loads the page. I can do all the scripts to get the link, but when I test the page title, I get the page I'm testing for, and not a new window at the top. How do I target this new window and check if the THAT page is loaded?

thanks

+4
source share
3 answers

The following worked for me with a form with the target = "_ blank" attribute, which sends a POST request to 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 - ie: assertTrue(.........); */ //Close the window and back to the main one selenium.close(); selenium.selectWindow(null); selenium.windowFocus(); 

The html code will look like:

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

You noted the RC question, so I assume this is not a Selenium IDE.

You can use something like selenium.selectWindow or selenium.selectPopUp or selenium.windowFocus to target a new window.

Itโ€™s very useful for me to use the Selenium IDE to capture the script, and then select โ€œParametersโ€ and then the desired programming format (Java, C #, etc.), and then use this snippet as the basis for the RC test.

+1
source

Based on the randomization of the name, I assume that I can scroll through the window names and select the unknown. This works, but not fully verified ...

  public function testMyTestCase() { $this->open("/"); $this->click("link=Sign in"); $this->waitForPageToLoad("30000"); $this->type("email", " xxx@gmail.com "); $this->type("password", "xxx"); $this->click("login"); $this->waitForPageToLoad("30000"); $this->click("link=Resources"); $this->waitForPageToLoad("30000"); $this->click("link=exact:http://100pages.org/"); $cc = $this->getAllWindowNames(); foreach($cc as $v ) { if (strpos($v, "blank")) { $this->selectWindow($v); $this->waitForPageToLoad("30000"); $this->assertRegExp("/100/", $this->getTitle()); } } } 
+1
source

All Articles