2016-09-02 40 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