2016-09-02 43 views
1

我想驗證了這樣的代碼通知消息的文本:如何驗證notify.js警報硒

<div class="notifyjs-corner" style="top: 0px; left: 45%;"> 
    <div class="notifyjs-wrapper notifyjs-hidable"> 
    <div class="notifyjs-arrow" style=""/> 
     <div class="notifyjs-container" style=""> 
     <div class="notifyjs-bootstrap-base notifyjs-bootstrap-success"> 
      <span data-notify-text="">Payment Created Successfully</span> 
     </div> 
    </div> 
    </div> 
</div> 

我的硒代碼:

String notify = BrowserSetup 
    .driver 
    .findElement(By.xpath("//span[contains(., 
    'Payment Created Successfully')]")) 
    .getText(); 
System.out.println(notify); 

價值在String notify是空的。

問題

我怎樣才能得到通知的文字?

參考:notify.js

+0

一次嘗試爲:'BrowserSetup.driver.findElement(By.cssSelector(「div中。 「))。getText();'讓我知道.. :) –

+0

這是拋出沒有這樣的元素例外 –

+0

你能告訴我什麼時候這個警報變成visibl è?? –

回答

1

查找元素通過Css Selector

wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".notifyjs-bootstrap-base.notifyjs-bootstrap-success>span"))).getText(); 

     String notify= BrowserSetup.driver.findElement(By.cssSelector(".notifyjs-bootstrap-base.notifyjs-bootstrap-success>span")).getText(); 
     System.out.println(notify); 

它工作時,我find element by cssSelector