IF inside While Selenium

Asked

Viewed 36 times

2

I am checking two fields using Selenium, when I have run the script I noticed that it never enters the IF condition, even meeting the requirements, always goes straight to ELSE.

Can anyone tell me what’s wrong and how to adjust this script? Follow the script:

String statusAssincProcess = null;  
String statusAssincProcess2 = null;

while (statusAssincProcess != "Finalizado" || statusAssincProcess2 != "Sucesso"){  
            Thread.sleep(1500);  
            dsl.clicarBotao("ctl00_ctl00_placeHolderMain_mainWebCad_btnFiltrar");  
            Thread.sleep(1500);  
            statusAssincProcess = dsl.obterTexto(By.xpath(  
                    "//*[@id=\"ctl00_ctl00_placeHolderMain_mainWebCad_grdServiceStatus_ctl00_ctl04_lbStatus\"]"));  
            statusAssincProcess2 = dsl.obterTexto(By.xpath(  
                    "//*[@id=\"ctl00_ctl00_placeHolderMain_mainWebCad_grdServiceStatus_ctl00_ctl04_lbFinalizadoComErro\"]"));  
            System.out.print("1" + statusAssincProcess);  
            System.out.print("2" + statusAssincProcess2);

            if (statusAssincProcess == "Finalizado" || statusAssincProcess2 == "Erro") {
                    Screenshot.tirar(navegador, "C:\\Users\\servflex050\\Documents\\TST_FATL\\printscreen\\"
                            + nometeste + "_" + Generator.dataHoraparaArquivo() + ".png");
                    statusAssincProcess = "Finalizado";
                    statusAssincProcess2 = "Sucesso";
                } else {
                    Thread.sleep(1500);
                    dsl.clicarBotao("ctl00_ctl00_placeHolderMain_mainWebCad_btnFiltrar");
                    Thread.sleep(1500);
                }
            }
  • 1

    Basically, to compare strings is used equals, nay ==. In the question that was suggested as duplicate there is a more detailed explanation

  • 1

    @hkotsubo thanks for the help! I read all that was said in the suggested question and I managed to understand better about when to use == or equals. Now the check is being done.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.