Tips for Verifying Success and Error Messages from a Login Form with Selenium Automation Testing

The code snippet provided below demonstrates how to perform a G-mail login using Selenium WebDriver.

package gmail_Login;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class Login {

    WebDriver driver;
    
    @Before
    public void setup() throws InterruptedException {
        driver = new FirefoxDriver();
        driver.get("https://gmail.com");
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    }
    
    @Test
    public void test() throws InterruptedException {
        WebElement username = driver.findElement(By.id("Email"));
        username.sendKeys("fake mail id");
        driver.findElement(By.id("next")).click();
    }

}

}

After providing a fake ID and clicking on the next button, an error message is displayed. To check the error message, additional code can be added in the test method.

Answer №1

To retrieve the error message text after clicking on the next button, follow these steps:

  1. Locate the error message element

    WebElement errorMessage=driver.findElement(By.id("errormsg_0_Email"));

  2. Retrieve the text of the error message

    String errorMsgText=errorMessage.getText();

  3. Verify the text with the expected error message text

    Assert.assertEquals(errorMsgText,expectedErrorMsgText);

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

Using Selenium to retrieve a list of elements located between two h1 elements

I'm currently working on a webpage that includes the following HTML snippet: <h1> ... </h1> <p> ... </p> <p> ... </p> <h1> ... </h1> <h2> ... </h2> <p> ... </p> <h3> ... &l ...

Tips for resolving the "unable to be scrolled into view" error in Selenium

While automating an application using Selenium, I encountered an error when attempting to click on an <a> tag: The element <a id="play_button" class="clickable myButton margin_t15 lang_57 medium_font" href="javascript:;"> could not be scroll ...

discovering the initial preceding sibling that matches, exclusive of any others

Is there a way to locate only the first preceding sibling that meets a specific criteria (e.g. class='a')? Currently, my search returns all matching nodes instead of just the first one. Here is an illustration of what I am referring to: tr class ...

What is the reason behind Jackson's decision to change a byte array into a base64 string when converting it to JSON

When dealing with a byte array in a DTO and converting it to JSON using Jackson's ObjectMapper, the byte array is automatically converted into a base64 string. This can be seen in the example below. @Data @AllArgsConstructor class TestDTO { privat ...

Export data from the user interface to an xlsx file and conduct a comparison to identify any recently added data

Requirement Overview: I have a web portal with data displayed in a table grid user interface. On a daily basis, I need to retrieve this data and transfer it to an Excel sheet. The following day, I must compare the new data with the previous day's info ...

When utilizing the JSON Wire Protocol, Selenium fails to employ the webdriver.firefox.profile feature

After launching the profile manager, I created a new profile named "foo" and set it as the default profile for Firefox. I then launched Firefox and closed it. Next, I started Selenium using the argument -Dwebdriver.firefox.profile=foo. The server's o ...

What is the best way to perform a mouseover using Python Selenium version 4.3.0?

ENV Python 3.10 Selenium 4 Hi, I am utilizing the following code: def findAllByXPath(p_driver, xpath, time=5): try: #return WebDriverWait(p_driver, time).until(EC.presence_of_all_elements_located((By.XPATH, (xpath)))) return WebDriverWait(p_driv ...

Steps for including screenshots in HTML reports created by pytest-html plugin using pytest and selenium

I've been attempting to incorporate screenshots of failed tests into the HTML reports created by the pytest-html plugin and pytest libraries. I tried following the steps mentioned in this helpful Question on Stackoverflow: How do I include screenshot ...

Navigating the Web Browser Console with Selenium: A Complete Guide

Currently utilizing Selenium version 2.46.0, I'm on a quest to debug various issues, particularly client-related ones. My goal is to extract all contents from the web browser console, including errors and warnings. My initial attempt involved the fol ...

An inquiry addressing the organization of a course framework intended to accommodate a mix of different categories

Currently, I am in the process of developing a simple JSON string parser and have encountered a specific scenario. My approach has been based on referencing the following RFC. RFC 8259:  The JavaScript Object Notation (JSON) Data Interchange Format. I ...

Select an option from a dropdown menu using Selenium with Python

Trying to choose an option from a dropdown list has been challenging for me. I've attempted various methods to click on the dropdown and then select my desired option, with the clicking part being successful but the selection process failing. Below a ...

Spring Boot REST API showcases the response outcomes in a specific format

I am looking to format the response result in a specific way: [ "author":"Author", "status_code":"200" "message":"GET", "description":"Description..." "data":{ &q ...

Choose the drop down selection in Selenium based on the variable that is provided as a string parameter

Context: Card stock - includes program details, stock location and country information Customer sell card screen - when selling a new card, the customer's address must be entered. Depending on the country inputted, certain fields (state/address line ...

What could be causing the certificate error in my Selenium?

Here is the code I am using to extract data from a website: from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.by import By import time from selenium.webdriver.support.ui import WebDriverWait from ...

Implementing Behavior-Driven Development in an Automated Testing Framework

My expertise lies in creating Automation frameworks with Selenium Web-driver, Java, and TestNG/ Junit. Within these frameworks, I streamline the automation of manual test cases and ease the workload of testers. However, I have a new task at hand where I m ...

Displaying the values stored in the "Salary" column

I'm currently struggling with trying to print a specific column from a Webtable, specifically the "Salary" column. I can't seem to figure out how to do this on my own, so any help would be greatly appreciated. import java.util.List; import org. ...

Locating checkboxes using Xpath expressions

Struggling with XPATH while using Selenium for my automation tests. I am trying to delete users and groups from the address book but I can't figure out the right locator to use. I've tried different Xpaths, but I feel lost and confused. The HTM ...

The tests in the Selenium Eclipse Test Suite are failing when executed together as a suite, but they pass successfully when run separately

I recently encountered an issue with my test suite for automating the login process on Gmail and clicking the Compose button. Here is a snippet of my TestSuite.xml file: TestSuite.xml <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <s ...

Can I receive the latest trending topics from YouTube?

My current project involves tracking the latest trends on Youtube. I am looking for a way to retrieve the JSON Object so that I can integrate it into my Java code efficiently. ...

Discovering a particular element involves iterating through the results returned by the findElements method in JavaScript

I am attempting to locate and interact with a specific item by comparing text from a list of items. The element distinguished by .list_of_items is a ul that consists of a list of li>a elements. I am uncertain about how to transfer the determined elemen ...