I have to handle a message coming from application on form filling. if it comes have to close the alert window using (X)button. problem is I'm not able to close it. directly close (.click()) works fine. but on condition when i say if alert is present then only close it scenario is not working. Any help is appreciated
try {
var Alert1 = element(by.xpath("//h2[text()='Job Role']/parent::div/following-sibling::div//span"));
Alert1.isPresent().then(async function(res) {
if (res) {
Alert1.click();
}
})
} catch (err) {
console.log(err)
}
})
it('async test case', async () => {
var Alert1 = element(by.xpath("//h2[text()='Job Role']/parent::div/following-sibling::div//span"));
if (await Alert1.isPresent()) {
await Alert1.click();
}
})
simple, readable and robust if you avoid .then