The WebDriverJS API provides code examples like the following:
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);
});
In this case, the title is "Google". It's also possible to modify the code as shown below:
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);
});
});
});
After these modifications, the title becomes "webdriver - Google Search". The status of the promise changes before the page finishes loading. This example is taken from the official API documentation and should be functional.
I came across an example of waiting on Stack Overflow, but I'm unsure how to implement it in working code using WebDriverJS since the API does not mention the "until" method.