【问题标题】:How to verify notify.js alert in selenium如何在 selenium 中验证 notify.js 警报
【发布时间】:2016-09-02 08:37:07
【问题描述】:

我想验证通知消息的文本,代码如下:

<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

【问题讨论】:

  • 尝试一次:BrowserSetup.driver.findElement(By.cssSelector("div.notifyjs-bootstrap-base.notifyjs-bootstrap-success")).getText(); 并告诉我..:)
  • 它没有抛出这样的元素异常
  • 您能告诉我此警报何时可见吗??
  • 其实在弹窗关闭后可见。
  • 那么你需要实现WebDriverWait 等到这个元素显示为new WebDriverWait(BrowserSetup.driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div.notifyjs‌​-bootstrap-base.noti‌​fyjs-bootstrap-succe‌​ss"))).getText(); 并让我知道..

标签: javascript java selenium notifications gettext


【解决方案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时它正在工作

【讨论】:

    猜你喜欢
    • 2017-07-10
    • 2018-05-16
    • 2019-12-28
    • 1970-01-01
    • 2015-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-19
    相关资源
    最近更新 更多