An effective way to confirm a notify.js alert using selenium

I am trying to validate the text of a notification message with the following code structure:

<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 script looks like this:

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

The variable String notify is currently returning an empty value.

Query

How can I extract the text from the notification?

For more information: notify.js

Answer №1

Locating element using Css Selector

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

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

This method works effectively when I locate elements by cssSelector

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Maintain Vue Router Query Parameters Across Parent Components

In my application, I have a component named Foo, which serves as the template for a route called app/foo. Within this component, there are child components that also act as templates for routes such as app/foo/bar and app/foo/baz. I've implemented a ...

What is the best method for extracting nested images from a Featherlight page on a website?

I am having issues getting the nested images and text from featherlight using web scraping. The code I have tried does not seem to work as it returns empty results. Here is an example of the nested images I am trying to scrape. I am unsure about what I m ...

The preference for the download directory in Selenium's Firefox profile is failing to be applied

Here is the code snippet I am working with: profile = webdriver.FirefoxProfile() profile.set_preference("browser.download.folderList", 2) profile.set_preference("browser.download.manager.showWhenStarting", False) profile.set ...

What is the purpose of using an img tag to retrieve a URL that is not an image?

Upon investigating a slow page load, I came across something interesting in the HTML: <img src="/ajax?action=askedAboutCookies" style="display:none" width="0" height="0" alt="" /> When the page loads, it sends a request but never receives a respons ...

Retrieve a unified data array from the provided data source

Below is a snapshot of my data const data = [{"amount": "600,000", "cover": null, "id": "1", "img": "636e56de36301.1.png", "make": "bmw", "model": "bmw ...

Utilizing JavaScript's Array.sort() method for sorting objects with varying properties

Currently, I am dealing with these specific Objects: let obj1 = { from: Date, to: Date } let obj2 = { date: Date } These Objects have been placed in an Array: let arr = [ obj1, obj2 ] My goal is to organize the objects within the array by using arr.sort( ...

The date format being sent by Angular to Java is incorrect, resulting in the inability to create an object in the

In my coupon system, I am experiencing an issue with the date format. The Java coupon bean has a date.sql startDate and endDate, while the Angular coupon model includes startDate:Date and endDate:Date in its constructor. However, when I display the dates o ...

Ways to verify if a JavaScript file has been successfully downloaded to the client's side

I encountered a strange issue with JavaScript recently. The webpage in question uses jQuery code for collecting data and performing input validation. If the validation passes, it then sends the data to the server. However, some users (around 10% or possib ...

Angular HTTP requests are failing to function properly, although they are successful when made through Postman

I am attempting to send an HTTP GET request using the specified URL: private materialsAPI='https://localhost:5001/api/material'; setPrice(id: any, price: any): Observable<any> { const url = `${this.materialsURL}/${id}/price/${price}`; ...

Dealing with the Back Button Problem in History API and History.js

Using Ajax to load the page presents a challenge when the user clicks the back button. Here is the scenario: Initial page (index.php) is loaded User clicks on a link The new page loads successfully via Ajax User clicks the back button The initial page is ...

Exploring unique forms with the turfjs polygon difference() function

While implementing the difference() function for my polygon map, I encountered a problem where unexpected shapes would appear or disappear when zooming in on the map. These shapes should not be there. The polygons involved are of type MultyPolygon and Poly ...

Open the HTML document and access the file contents

I'm having trouble reading a text file from my computer onto a website. It works fine in Internet Explorer, but won't work in Chrome. I don't have much experience with HTML, so any help would be much appreciated! <html> <body> ...

Could not locate module: Issue: Unable to resolve './Firebase'

I'm a beginner with React and I've been working on setting up Firebase in my React application. import firebase from 'firebase/compat/app'; import 'firebase/compat/auth'; import 'firebase/compat/firestore'; var fire ...

Leverage socket.io in various routes within a node.js application

In my Node.js application, I have various routes defined in the router.js file. Now, I want to implement socket.io in every route to enable real-time communication between my Node.js and React.js applications. However, the structure of my Node.js applicati ...

How can we display or conceal text indicating the age of a patient based on the value returned from selectedPatient.age in a React application?

Hello, I am looking to dynamically display the age in years on the screen based on the value retrieved from selectedPatient.age, toggling between visible and hidden states. import React, { useContext } from 'react'; import { useHistory } from &ap ...

Adjust the size of items using a background image that covers the element

I'm struggling with a seemingly simple task here. I've been experimenting with different methods, but I just can't seem to grasp it. On the front page of my website, there is a cover section that contains a logo and a button: <section i ...

Issue with starting activity in a Service for API versions 23 and below

Recently, I encountered an issue with a Thread in my service where calling the startActivity method works perfectly when using API 24 or higher. However, it fails to work when using API 23 or lower. The code in the Thread class looks like this: private I ...

What is causing the jQuery functions to not be executed in sequence?

Whenever I click the Start button, my function is supposed to run a cycle for 10 iterations. Each iteration generates a number between 1 and 7, which then triggers a series of functions on different objects. The problem is that these functions are not runn ...

Click on the first jQuery element

I'm currently dealing with a menu that has multiple levels. My goal is to create a functionality where clicking on a first-level element will add the class .ubermenu-active to it, while also removing this class from any other first-level elements. $( ...

Error: Unable to retrieve any information from the database

I am encountering an issue where I am getting a SQL Exception: java.sql.SQLException: No data found. I am unable to identify the source of the problem here. Can someone please assist me with this error? My apologies for seeking help. try{ Class ...