Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

319
Vistas
"For" loop not picking up the "if" condition when it checks for object using xpath

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:

  1. Go to a webpage and search for a certain criteria.
  2. On populated results, grab all values in a single column. Then in the same search box, search for each value grabbed from the column.
  3. In the results, click on Delete for the populated result.
  4. Some rows will throw an exception, in which case, we want to go back and try the next item in the column value array until all items are either deleted or the leftover items are all the ones that throw exception.

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.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

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')) {
  ...
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda