0
I need to make a looping in which it stops running only when a specific element becomes visible.
It must click the filter button and check if the element is visible, if the return is false, it performs the process again. If the return is true, it will enter the IF I will create.
I don’t know if I need to use while with a for or another function...
Follow the code I have at the moment.
//CLICA EM FILTRAR E ESPERA O STATUS FINALIZADO COM SUCESSO
dsl.clicarBotao("ctl00_ctl00_placeHolderMain_mainWebCad_btnFiltrar");
Thread.sleep(1500);
String statusAssincProcess = "Iniciado";
String statusAssincProcess2 = "Sucesso";
while ("Iniciado".equals(statusAssincProcess) || "Sucesso".equals(statusAssincProcess2)){
Thread.sleep(2500);
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\"]"));
if ("Finalizado".equals(statusAssincProcess) || "Erro".equals(statusAssincProcess2)) {
Screenshot.tirar(navegador, "C:\\Users\\servflex050\\Documents\\TST_FATL\\printscreen\\"
+ nomeTeste + "_" + Generator.dataHoraparaArquivo() + ".png");
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\"]"));
}
if ("Finalizado".equals(statusAssincProcess) || "Sucesso".equals(statusAssincProcess2)){
Screenshot.tirar(navegador, "C:\\Users\\servflex050\\Documents\\TST_FATL\\printscreen\\"
+ nomeTeste + "_" + Generator.dataHoraparaArquivo() + ".png");
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\"]"));
}
}
First, thanks for the comments, just so I realized how polluted my code was. Now it’s much better! I couldn’t really explain what I need, but I think it’ll be easier to understand. And insert the data into the filters on the screen and click the "filter" button to show a grid with the processes and their status. For the grid to appear, you need to run an internal process on the server that can take up to 3 minutes, so I need the grid to appear on the screen first. After that I do all this status check. I think it’s now clearer.
– Allan Costa
The grid appears with status1 "started" and Status2 "success". After finishing they are changed to status1 "finished" and Status2 "successful" or "error". Then the status execution will be done until they are different from "started" and "successful".
– Allan Costa
Okay, with the code that I passed on, I believe that you can achieve your goal, you populate the fields and then run those lines of code, that should cover your goal, that
do while
, in my example then it will stop repeating once the status is finished + success, but it is not what you really want, in which case you should change the last line towhile("iniciado".equals(statusAssincProcess) && "sucesso".equals(statusAssincProcess2));
I’ll edit the answer to cover it.– Spencer Melo
And watch out for uppercase or lowercase.
– Spencer Melo
When I click filter and the grid is not yet available, it will not return the execution error when trying to pass the status to the variables?
– Allan Costa
I edited the end of the answer and added how to stop using Thread.Sleep, you should make use of Webdriverwait in your class
dsl
.– Spencer Melo
The code perfectly solves the treatment of status and Sleep, but it still does not solve the question of the element I need to verify. I need to click search (button
id=xyz
) check whether the elementid=abc
is visible on the page. If it is visible, I have atrue
and follow with the script if the return isfalse
, i do the run of "click search", and "check element" again.– Allan Costa
Let’s go continue this discussion in chat.
– Spencer Melo