0

您好我正在嘗試使用selinuim web驅動程序編寫一個java腳本來驗證用戶是否已經在註冊過程中存在。 當用戶查看在我的網站上,他點擊「成爲tinze」 home page of my site用selenuim檢測窗體中的文本

然後他完成對形式和集團「加盟」 sign up form

如果郵件已經存在messag「電子郵件已存在」顯示。 Email Already exist

我的腳本成功完成表單,但是這不可能檢測消息「電子郵件已存在」

這裏是郵件的HTML代碼,我試着去探測

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

這裏是我用來驗證文本是否顯示,但它始終顯示我檢測到的代碼

 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("[email protected]"); 
    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");} 

當我嘗試在這裏是結果even message displayed it can t be detected by selinuim

回答

0

這爲我工作。

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"); 
     } 
+0

即使我寫的「檢測」新郵件的messag顯示 –

+0

沒有它不牛逼的工作是有一個諾特爾方式? –

+0

如果上面的代碼不起作用請提供我的URL和使用的emalID將查看它。 –

0

也許元件不總是存在的,但一些JavaScript顯示或隱藏取決於結果從「已存在」檢查元件(或父)。

也許試試isDisplayed()方法?

isDisplayed() vs isVisible() in Selenium

+0

thnks for ur respons但我沒有工作,它顯示我「文字未檢測到」 –