Ensuring Message Accuracy with Selenium in C# Development

I am a beginner in the world of test automation and I am looking to retrieve the value from a web element labeled "message-success failed", which displays the message "This customer name already exists".

Here is what the CSS looks like

Even though I attempted the following code, it unfortunately did not succeed:

 Console.WriteLine(
     PropertiesCollection.driver
                         .FindElement(
                             By.ClassName("message-success failed"))
                               .GetCssValue("li"));

The PropertiesCollection class can be found here:

 class PropertiesCollection
    {
        // Auto-implemented property
        public static IWebDriver driver { set; get; }
    }

The error encountered while attempting this is as follows

Answer №1

One issue is that you are unable to pass multiple classes to the ClassName selector, so try using the .message-success.failed CSS selector instead. To retrieve the message text in this scenario, simply use the Text:

Console.WriteLine(PropertiesCollection.driver.FindElement(By.CssSelector(".message-success.failed")).Text);

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

The values in my JavaScript don't correspond to the values in my CSS

Is it possible to retrieve the display value (display:none; or display:block;) of a div with the ID "navmenu" using JavaScript? I have encountered an issue where I can successfully read the style values when they are set within the same HTML file, but not ...

Is it possible for a Python and R file to collaborate and share a single webdriver session?

I've been working on a web scraper using RSelenium, but have found that certain tasks are better suited for Python. To streamline this process, I've created a .Rmd file with code snippets in both R and Python. The RSelenium side of the project i ...

What is the best way to arrange divs in Bootstrap 4?

Is there a way to reorder two divs that are next to each other in a row on mobile? I want the right side div (col-md-9) to be displayed first. I attempted using flex ordering, but unfortunately it caused layout issues throughout my site. <div class="r ...

Discovering the IDs, Names, and Classes of CSS Elements Using Selenium

I'm facing a challenge in finding the identification of a specific element. Most examples I have come across on the Internet have clear ids and names for elements. However, the webpage I am currently testing has elements that lack ids or names. They a ...

Where is the appropriate location to input parameters in Selenium testing?

What is the best approach for passing parameters? The code snippet below has been modified to focus on relevant pieces... I currently pass in login parameters directly within the [TestMethod], rather than within the LoginPage class object. Is this the co ...

What is causing this error to appear when attempting to access the search results panel with the links for each result?

I'm facing numerous errors while attempting to create a basic app using Selenium and C#. My goal is to develop an application (either in a windows or console environment) that launches a browser, navigates to the Google page, searches for "APPLES," a ...

Storing user input in an existing text file using ASP.NET MVC

What steps should I take to store user form input from a view into an already existing text file using the ASP.NET MVC framework? ...

SVG path with dynamic elements

Consider the following SVG: <svg xmlns="http://www.w3.org/2000/svg" width="237" height="129" viewBox="0 0 237 129" fill="none"> <path d="M228 1H9C4.58172 1 1 4.58172 1 9V91V104V127L20 111.483L228 112C232.4 ...

JQuery - Triggering mouseenter/hover event only on top-level menu items, excluding the nested submenu items (list items that are not within nested lists)

I have a complex navigation menu structure with nested lists, and I'm struggling to trigger an event only on the top-level items when hovered. Despite trying different jQuery selectors and methods, such as using the NOT selector or targeting direct ch ...

The behavior of `(Bitmap)image` is not the same as that of `new

Here is a scenario where a test I wrote is currently failing: var unusableColor = Color.FromArgb(13, 19, 20, 19); var retrievedColor = Color.Empty; var tempFile = Path.GetTempFileName(); using (var bitmap = new Bitmap(1, 1)) { bitmap.SetPixel(0, 0, u ...

Tips on updating the initial value of a select box or placeholder?

Here is a select input: <select name="" id=""> <option disabled hidden selected value=""> default </option> <option value="2">2</option> <option value="3">3</option> <option value="3">3</option> ...

Using Docker to run Selenium tests with C# through a Web API

Currently, I am conducting a test proof of concept for a web API. Within this web API endpoint, I am running Selenium tests. Although everything runs smoothly on my local setup, I encounter an error when running the tests on a Docker image: System.Excepti ...

Using Java in Selenium WebDriver to compare images

In my current work with Selenium WebDriver, I am facing a challenge in comparing two images during automation. The method I am currently using involves pixel comparison, but it presents an issue when the browser size or system settings change during the au ...

Using jQuery to apply gradient fill to SVG elements

Is it possible to create a gradient fill in an SVG with two or three colors dynamically? Currently, filling an SVG path with just one color can be done easily. Radial gradients are an option but don't offer much flexibility as colors have to be define ...

Is it possible to access and view email responses through the Gmail API?

foreach (var part in emailInfoResponse.Result.Payload.Parts) { if (part.Parts != null) foreach (var innerPart in part.Parts) { if (innerPart.MimeType == "text/plain") { body = innerPart.Body.Data; ...

Using Javascript to dynamically swap images within a div as the user scrolls

Can someone help me achieve a similar image scrolling effect like the one on the left side of this website: I am looking to change the image inside a div as I scroll and ensure that the page doesn't scroll further until all the images have been scrol ...

Searching for an element by a partial elementId or UID using XPath in Appium

Currently, I am engaged in automating a test for an iOS application. I am utilizing the Appium desktop client (version 1.15.1) on MacOS (version 10.15) to find an element on iPhone 11 (iOS version 13.3) using the Inspector with specific attributes: view th ...

Access the LocalHost from a device connected to your own personal hotspot

Apologies for any language barriers, I am in the process of developing an application that allows for file transfer via Wi-Fi. To accomplish this, I set up a simple HTTP server and designated the "E:\transferfile" folder as the root of localhost. I th ...

How can I package chromedriver with pyinstaller?

I am in the process of using pyinstaller to create an executable version of my Python script. Within the script, I have imported certain modules as shown below: from selenium import webdriver from selenium.webdriver.chrome.options import Options etc... O ...

Fetching large images with "fill" layout in NextJS

I am currently using Cloudinary to serve correctly sized images, however, it appears that NextJS image is always fetching with a width of 3840, instead of the fixed value. <Image src={loaderUrl(logoImage)} alt="" role="presen ...