In the following code example, clicking on the anchor with id openPage
should open a new page. The test only succeeds, when using a short delay sleep(1000)
as getCurrentUrl
does not seem to wait until the page is loaded.
var element = driver.findElement(webdriver.By.id('openPage'));
element.click();
driver.sleep(1000);
var promise = driver.getCurrentUrl();
promise.then(function (url) {
assert.strictEqual(url, 'page title');
});
What would be the proper (async) way to code this without using a delay ?