开发者

IE and Selenium: window.createPopup()

I've been playing with Selenium lately, trying to create tests for an IE only application. Things were progressing (though slowly as without the recorder plugin I had to resort to trial and error to try to find the appropriate element paths), but now I'm stuck with a problem related to popup menues.

Most of the application actions are triggered from a pop开发者_如何学Pythonup menu created with javascript window.createPopup() and I can't seem to find a way to send events to elements inside the popup.

Maybe I should be selecting the popup like I do for windows opened with window.open(...), which are working fine BTW. I tried assigning a name to the popup menu returned by createPopup() and treating it the same way I treat windows but that doesn't seem to be working.

Does anybody knows if this is supposed to work? Any help will be appreciated.

Thanks,


Unfortunately, no. window.createPopup isn't accessible to Selenium. Being an IE only feature it has really limited portability and generally isn't a best practice. I know that's of little consolation to you, because I assume your stuck with someone else's code that's used createPopup.

The real problem is that craeatePopup doesn't add anything to the DOM. Try opening a popup object and viewing it's source. You'll see this:

<html><body></body></html>

So there's nothing really there for Selenium to grab hold of.

What does the popup do for your application? You indicated it provides some navigation, can you just navigate to those pages directly?


if you know the name of the window you can do

selenium.click("elementToLaunchPopup");
selenium.waitForPopup("nameOfWindow",30000);
selenium.selectWindow("nameOfWindow");
// rest of your test

To get back to the main window you will need to selenium.selectWindow("null");


I am using selenium 2.0b3 with InternetExplorerDriver. I found something that do the trick.

In your js save a reference to the popup window.

  var popUp= window.createPopup();

Then in your java code:

public Object executeJS(String code){
    JavascriptExecutor js = (JavascriptExecutor) driver;
    return js.executeScript(code);  
}
WebElement popUp =(WebElement) 
     executeJS("return  popUp.document.documentElement;");

This will give you a reference to the page and you can find elements normally.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜