如何在selenium中验证notify.js警报

时间:2016-09-02 08:37:08

标签: javascript java selenium notifications gettext

我想验证通知消息的文本,其中包含以下代码:

<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

1 个答案:

答案 0 :(得分: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

时工作