Validate element in Selenium Webdriver

Asked

Viewed 1,305 times

0

I have a certain test, where I programmed to put some plates and then to it click on the button (forward) and then on the button (finish). Only that depends, by the fact that it has some plates that do not need to press the button (forward), but only on the button (finish). I wanted to know how to make him understand that when the (next) button appears he click and then click on (finish), and at the same time when this (next) button does not appear, he jumps and goes to the (finish) button. I’m waiting for someone to answer

3 answers

0

Edvaldo Torres,

Try to do the following:

if(botaoAvancar.isDisplayed()){
   botaoAvancar.click();
   botaoConcluir.click();
}else{
   botaoConcluir.click();
}

isDisplayed() -> this method validates whether the element is displayed on the screen or not.

Abç.

0

When I needed to implement a logic similar to this one I used the Expected Conditions in conjunction with Webdriverwait.

I used Selenium for python. But this is the idea.

That number 10 is the waiting time.

from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

elemento = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "idelemento")))

I hope I’ve helped.

0

1- when the (next) button appears, click it and then click on (finish). A: By the way you didn’t put a waiting team after the click of the next button, put a team on the button after it clicks forward, make the system wait a little longer and then click on finish.

2-Only that depends, for the fact that it has some plates that do not need to press the button (forward) but only on the button (finish). So in this case you have to create a function in your project that identifies which enrolls the (next) button can be clicked.

Example enrollment 12345677 this enrollment does not need to have the button (forward) just finish, so you will make this code

        IwebElement BtAvancar = Driver.GetElement(By.Id("IdBtnAvanar");
        IwebElement BtConcluir = Driver.GetElement(By.Id("IdBtnConcluir);

         public void AcaoBtn()
        {
            //Inserindo a mátricula que não precisa clicar no botão de avançar
           IwebElement CampoMatricula = Driver.GetElement(By.Id("CampoNumMatriula"));
           CampoMatricula.SendKeys("12345677");

           //Time de Espera
          System.Thrading.thread.sleep(2000);

          //Verifico se na minha página tem o botao de avançar
          if(driver.PageSource.Contains("Avançar"))
          {
             //Crie uma função que ignore o botão
          }

          if(driver.PageSorce.Contains("Concluir")
          {
                BtConcluir.Click();
          }

       }

For now that’s just a simple answer, because I don’t know what the page code looks like, if you can put the page code just to know how this writing will be easier to help and understand your problem!

Browser other questions tagged

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