0

I am trying to write a java script using selenium web driver to verify if a user already exist during the sign up . when a user access to my website he click on "become a tinze" home page of my site

then he complete the form and clique on "join" sign up form

if the mail already exist message "Email Already exist" displayed .Email Already exist

my script successfully complete the form but it can't detect the message "Email Already exist"

here is the html code of the message that I'm trying to detect

<p name="already" style="color:Red;" class="ng-binding">Email Already exist</p>

and here is the code I use to verify if the text is displayed but it always show me detected

     driver.findElement(By.cssSelector("span.ng-scope")).click();
    int v = 0,i=0;
    System.out.println("enter while");
       while(v==0){
   try{
     WebElement txtbox_username = driver.findElement(By.id("firstname"));
        if(txtbox_username.isDisplayed()){
            v=1;
            System.out.println("Complete the forme");}}
    catch(NoSuchElementException nsee){
    i++;
     System.out.println("Try number:"+i); }}  
     driver.findElement(By.id("firstname")).sendKeys("haha");
     driver.findElement(By.id("lastname")).sendKeys("haha");
     driver.findElement(By.name("email")).sendKeys("hah@ahla.com");
     driver.findElement(By.id("password")).sendKeys("yassiryakhlaf");
      driver.findElement(By.id("signmeup")).click();
      System.out.println(driver.findElement(By.id("firstname")).getText());  
      try {Boolean display =  driver.findElement(By.xpath("//p[@name='already']")).getText().equals("Email Already exist");
      if (display){System.out.println("detected");}
      else{System.out.println("not detected");}
      } catch (NoSuchElementException e) {System.out.println("nott detected");}

when I try here is the result even message displayed it can't be detected by selenium

Cœur
  • 37,241
  • 25
  • 195
  • 267

2 Answers2

0

This worked for me.

try {
            boolean boo = driver.findElement(By.xpath("//div[@id='MsgAfterSignup']/center/p")).isDisplayed()
                && driver.findElement(By.xpath("//div[@id='MsgAfterSignup']/center/p")).getText()
                        .equals("Email Already exist");
            if (boo){
            System.out.println("detected");
            }
            else{
                System.out.println("Not detected");
            }
        } catch (Exception e) {
            System.out.println("Not detected");
        }
Girish Bellamkonda
  • 491
  • 1
  • 8
  • 17
0

Perhaps the element does always exist, but some javascript shows or hides the element (or a parent) depending on results from the "already exists" check.

Maybe try the isDisplayed() method?

isDisplayed() vs isVisible() in Selenium

Community
  • 1
  • 1
MonkeyTester
  • 139
  • 5