WebDriver not waiting for a popup

1,997 views
Skip to first unread message

dl

unread,
Aug 30, 2011, 2:19:15 PM8/30/11
to Selenium Users
Creating a Selenium WebDriver script to deal with a popup created by a
web app.

What I'm seeing is that the popup is launched but the script is not
waiting before trying to access the popup. There is a waitForPopup
method on the selenium object but I don't know how to get the selenium
object. I have a WebDriver object and I suspect that the Selenium
object is for a different API.

The way I tried to create a Selenium object doesn't seem right:

WebDriver driver = new InternetExplorerDriver();
WebDriverBackedSelenium selenium = new
WebDriverBackedSelenium(driver,"http://webguiders.com/");

although it did provide me with an object. When I tried to use the
object, as so:

WebElement link = driver.findElement(By.linkText("guider"));
link.click();

selenium.waitForPopUp("Guider", "60000");

it threw a NoSuchWindowException exception.

Secondly I see suggestions that I should use WebDriverWait, as in ...

WebElement el = (new WebDriverWait(driver, 10)).until(new
ExpectedCondition<WebElement>(){
public WebElement apply(WebDriver driver) {
return driver.findElement(By.something('...'));
}
});

… to wait for an element to appear but Unless I can call ...

driver.switchTo().window("MyWindow");

… won't the WebDriverWait wait for the element to appear on the main
page and not the popup? I need to switchTo() to direct future
commands to the popup but it's the switchTo() that is failing.

Anyone have a WebDriver example of launching and waiting for a popup?

Luke Inman-Semerau

unread,
Aug 30, 2011, 2:43:14 PM8/30/11
to seleniu...@googlegroups.com
Yep... not formated well because of email, but here's one: http://groups.google.com/group/selenium-users/msg/fa706b2ee4e7cd97


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.


dl

unread,
Aug 30, 2011, 4:08:07 PM8/30/11
to Selenium Users
Well, that worked for me but it seems weird. Essentially you get all
the window handles before you launch the popup, then you launch the
popup, then you wait until there's window handle that wasn't there
before.

I assume this is some workaround? It can't be the way Selenium's
supposed to work is it? Dealing with popups is common enough for there
to be a working mechanism built in isn't it?

Also, the window handle being returned appears to be in the format of
a UUID and that's what your code passes to the
driver.switchTo().window() call. Why does that work? Shouldn't it be
the window title or the programmatic window name (2nd argument in
window.open()).

Thanks for giving me code that works! Anyone have any answers to the
other questions?

Luke Inman-Semerau

unread,
Aug 30, 2011, 4:36:39 PM8/30/11
to seleniu...@googlegroups.com
So, in the most basic cases where a link is specified with a "target" or the onclick="window.open(....)" it will wait for the window to be open... but in a lot of cases the clicking is actually triggering some relatively complex javascript that calculates certain things and then opens the popup. In those situations webdriver doesn't know the browser is still processing something because the click event completed.

The window handles is as you say a unique id (don't think it's universal though)... isn't that better to refer to?  The switchTo().window() can pass in a window name, but sometimes those are blank and in those cases there could be multiple of them. So... name isn't a great identifier, but can work.... but that's why I like to use the Handle instead.  Title is even worse, since on some sites they just have the same title for multiple pages / windows.

dl

unread,
Aug 30, 2011, 4:42:48 PM8/30/11
to Selenium Users
I guess that's the case here. The click does call a bunch of
Javascript. That makes some sense now.

Yeah, if you have a window id it's probably pretty unique. I just
didn't know that the method would really work with it. I wouldn't
think having that window ID would be very common except with your
code.
Reply all
Reply to author
Forward
0 new messages