Reputation: 26150
I understand that the top level webdriver API doesn't provide access to the page load event handler, but is there any way (including sending a command directly to the server through the REST interface) to make a call directly to the selenium server to force the page load block behavior? I know about the wait for element hack, but I'd rather go straight to the source if at all possible. The specific problem I'm having is a page that makes a JS call when a button is clicked that displays a modal dialog on the page while some backend processes happen, then forwards the browser to a new page once the backend work is complete. Since the click action doesn't directly trigger the new page, selenium doesn't block on the event (and I wouldn't want it to in all cases anyway).
I've looked through the Command class for any promising looking commands, but didn't see anything. I found http://code.google.com/p/selenium/wiki/JsonWireProtocol but it didn't help either...
Upvotes: 2
Views: 1699
Reputation: 1510
Thats a tricky one.
Accessing the http status in selenium/webdriver is not very handy. I would recommend a pragmatic way. IMO the wait for element approach is not a hack, its the proper way to do it. In your case I would wait for selenium.getLocation() or webdriver.getCurrentUrl() contains an expected value.
Something like this:
webDriverWait.until(new Function<WebDriver, WebElement>() {
@Override
public WebElement apply(WebDriver driver) {
//TODO: pass expected url as parameter
boolean expectedUrl = driver.getCurrentUrl().contains("your redirect url");
if (expectedUrl) {
//If not null is returned, we have found something and waitUntil stops
return new RemoteWebElement();
}
//try again
return null;
}
});
Upvotes: 1