Search code examples
javascriptjavaseleniumnotificationsgettext

How to verify notify.js alert in selenium


I want to verify the text of notification message which has code like this:

<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>

My selenium code is:

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

The value in String notify is empty.

Question

How can I get text of the notification?

For reference: notify.js


Solution

  • Find element by 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);
    

    It is working when I find element by cssSelector