The WebDriverJS API says I can write code like this:
driver.get("http://www.google.com");
driver.findElement(webdriver.By.name("q")).sendKeys("webdriver");
driver.findElement(webdriver.By.name("btnG")).click();
driver.getTitle().then(function(title) {
console.log(title);
//assertEquals("webdriver - Google Search", title);
});
Here title is "Google". I can modify the code:
driver.get("http://www.google.com");
driver.findElement(By.name("q")).sendKeys("webdriver");
driver.findElement(By.name("btnG")).click().then(function(){
/*WebDriverWait.until(function() {
driver.getTitle().then(function(title) {
console.log(title);
title = "webdriver - Google Search"
});
});*/
driver.sleep(3000).then(function() {
driver.getTitle().then(function(title) {
console.log(title);
});
});
});
And now the title is "webdriver - Google Search". The promise changes status before the page has a chance to load. This example comes from the API documentation so it should work.
I saw an example of waiting on SO, however I do not not know to translate this to working code in WebDriverJS and the API makes no mention of "until".