Currently, I am developing a JavaScript-based webdriver automation to test a web application. Below is a snippet of the code I have written:
var selenium = require('selenium-webdriver');
By = selenium.By;
until = selenium.until;
driver = new selenium.Builder().
withCapabilities(selenium.Capabilities.chrome()).
build();
getItems = async function() {
try {
var itemsXpath = '[xpath expression]';
var items = await driver.findElements(By.xpath(itemsXpath));
log(items.length + ' items found');
...
}
catch(err) {
log(err);
}
}
The initial code runs successfully. However, when I substitute the await
line with:
var items = await driver.wait(until.elementsLocated(By.xpath(itemsXpath)),60000);
it does not behave as expected. Neither the subsequent log()
nor the one in the catch()
block are displayed.
After reviewing the documentation, it was my understanding that if there were items on the webpage that match the XPath locator, either approach would work and return the elements. However, for nonexistent elements, the second method should wait for them to be visible (up to 60000 ms).
It's worth noting that even if the items are present on the screen at the time getItems()
is invoked, the alternative implementation fails. Additionally, the execution finishes before the timeout specified in driver.wait()
.
Is there a misunderstanding on my part regarding this functionality? If so, could someone provide clarity on what might be occurring in this scenario?