I am a newbie to JS and am facing an issue for which I cannot find a solution for. I am writing a script to automate a "clean up" process using Karate/Selenium.
Scenario:
I have this so far:
driver.input('#searchField', ['Mobile', Key.ENTER], 200); //here I am using Karate/Selenium to enter the search criteria on the UI.
function() {
var searchResult = false;
searchResult = driver.exists('//table//tr');
var errorPage = driver.exists('#exception');
do {
var deleteCriteria = driver.scriptAll('//table//tr//td[3]', '_.innerText'); //Here I am grabbing actual values I need to search by across the entire column and putting it in array form.
for (i = 0; i < deleteCriteria.length; i++) {
driver.input('#searchField', [deleteCriteria[i], Key.ENTER], 200);
driver.click('#deleteBtn');
driver.click('#deleteNumber');
driver.delay(10000);
if (errorPage) {
driver.back();
driver.delay(10000);
driver.back();
driver.delay(10000);
} else {
continue;
}
}
} while (searchResult);
}
Problem: When the exception page does display, the IF block is not initiated. The script fails trying to find the search box to search again. Please advise.
PS- I understand my "while" is not correct yet. I will fix it once the problem in question is resolved.
The code var errorPage = driver.exists('#exception'); runs once and stores the state at that moment in time.
If you want to know if it exists at the current moment in time, you need to look for it again.
if (driver.exists('#exception')) {
...
}