Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

327
Visualizações
"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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda