I am currently in the process of migrating tests from webdriver and Java to webdriverjs, and I have a question regarding the functionality. Can someone help me understand why this code snippet works?
driver.get('http://www.google.com');
driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');
driver.findElement(webdriver.By.name('btnG')).click();
driver.wait(function() {
return driver.getTitle().then(function(title) {
return assert.equal(title, 'webdriver - Google Search');
});
}, 2000);
The variable 'title' indeed contains 'webdriver - Google Search'
On the other hand, this version fails:
driver.get('http://www.google.com');
driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');
driver.findElement(webdriver.By.name('btnG')).click();
driver.wait(function() {
driver.getTitle().then(function(title) {
assert.equal(title, 'webdriver - Google Search');
});
}, 2000);
In this case, the 'title' variable captures the title of the homepage instead of the search results page.
Thank you!