Answer the question
In order to leave comments, you need to log in
How to return an unresolved promise?
I work with Selenium, and I want to highlight a separate function. Structure of the existing code:
driver.then(_=> driver.wait(until.elementLocated(By.css()))
.then(_=>driver.findElement(By.css()).click());
driver.then(_=> driver.getElementByCss().click());
function getElementByCss(path){
return driver.wait(until.elementLocated(By.css()))
.then(_=>driver.findElement(By.css()))
}
Answer the question
In order to leave comments, you need to log in
First, this won't work because promises don't have a click() method, and your
driver.getElementByCss().click() call literally reads: call the driver.getElementByCss() function result method you want to was a promise.
For that matter, it should be something like this:
driver.then(_=> driver.getElementByCss().then(el=>el.click()));
driver.prototype.getElementByCss(){
return new Promise((resolve, reject) => {
driver.wait(until.elementLocated(By.css())).then(_=>resolve(driver.findElement(By.css()));
});
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question