Unable to locate an element on the webpage due to a JavaScript-based error, which then becomes hidden after a few seconds. (Registration form)

While completing a registration form, I encounter a hidden message after clicking on the register button. Struggling to locate this elusive element has been an ongoing challenge for me.

Unfortunately, my attempts to find the element have been unsuccessful, preventing me from catching the error and progressing with the registration process.

I could really use some input on this issue. I've tried using methods like isDisplayed() and isEnabled(), but none of them seem to work. Even creating custom methods to handle the situation hasn't resolved the problem.

//isElementPresent is a custom method I've created
//Appointment.PhoneNoMatch is the locator stored in objectrepository

boolean phoneError = isElementPresent(Appointment.PhoneNoMatch);

if (phoneError == true)
{
    System.out.println("Phone number already exists");
    break;
}
else
{
    //Continue with the remaining execution
}

public boolean isElementPresent(By by) throws Throwable {
try {
   List<WebElement> ele = driver.findElements(by);
   if (ele.size() > 0) {
   return true;
}
else
{
   return false;
}
}
catch (Exception e) 
{
System.out.println(e.getMessage());
return false;
}
}

Answer №1

The browser generates this message when the field has the required property set in HTML 5, making it not easily detectable as a standard DOM element. For tips on how to identify and handle this situation, refer to this helpful answer: .

If encountering difficulties during testing, consider using JavaScript to remove the property and focus on server-side validation, such as checking for relevant HTTP error codes.

For further insights, explore these resources: Chrome popup Please Fill Out this Field and Check if "Please enter an email address" message appears

Answer №2

After spending days puzzling over this issue, I finally cracked the solution.

Trying every possible fix with no success, I eventually resorted to using getAttribute to retrieve the class, then used getText() to compare the text and identify errors.

I observed that when there was an invalid or blank entry, the class attribute changed to "focused" as the focus shifted to that specific element.

//Appointment.EmailIDError is the locator stored in the object repository
String ClassName1 = driver.findElement(Appointment.EmailIDError).getAttribute("class");
       if(ClassName1.equalsIgnoreCase("form-group label-floating has-error is-focused"))
         {
          System.out.println("Email ID is Invalid");
         }

If you need further clarification, feel free to reach out to me.

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

Having issues with passing data to a Modal on eventClick using FullCalendar with ReactJS, receiving a "cannot read property of undefined" error. Any advice on how

My MERN stack application utilizes the FullCalendar plugin, even though I am aware that mixing jQuery with React is not ideal. Unfortunately, I am a novice developer and running behind schedule. The goal is to allow users to click on an event on the calen ...

Retrieve Static Property Values Using jQuery/JavaScript in Backend Code

My challenge is to fetch the Max value and Percent value into a jQuery function. I attempted to retrieve these values using hidden variables and Session variables on page load, but they always return 0. Here are the properties: public static int Max { ...

Dynamic CSS Class Implementation with KnockoutJS

Greetings, I am seeking assistance as I am new to KnockoutJS. I am working with a class named green-bar that I need to activate when two particular states are true. Unfortunately, the solution I came up with below is not functioning correctly, and I'm ...

Understanding Variable Scope in JavaScript: How Variables are Accessed in Different Functions

I've been experimenting with a script that utilizes jQuery's get function to transfer data to another page and display the returned information as an alert on the current page. My goal is to send both the search field value from an input form (wh ...

How do prototype, the $.extend method, and the concept of "return this" all connect with each other?

I've been assigned a legacy project, and I find myself puzzled by the purpose of this code. define(['jquery', 'components/BaseComponent', 'bootstrap'], function( $, BaseComponent, bootstrap ) { 'use strict&a ...

Retrieve the element by clicking on its individual tooltip

I am currently struggling with a jQuery UI tooltip issue. Specifically, I would like to retrieve the element that the tooltip is associated with when clicking on it. My Approach So Far $(".sample").tooltip({ content: function () { return $(t ...

Is there a way to ensure a web driver can detect an element even when the page is continuously refreshing?

I am facing an issue while running a script on a webpage that contains a list of links to news articles. The problem arises when the script clicks on the link and waits for the "h1" element to load before checking its text for specific keywords. However, o ...

When using res.redirect in Express, it not only redirects to a new URL but also allows you to access the HTML

I'm having an issue with redirecting a user to a login page when they click a button. Instead of being redirected, I am receiving the html source code and nothing is happening. My express redirect method is as follows: function customRedirect(req, ...

Designing versatile buttons with HTML

When accessing the website on a phone, I have trouble seeing and tapping on these two buttons because they are too far apart. I would like to change it so that once a file is selected, the 'choose file' button will be replaced by the upload butto ...

The WebDriverWait timeout follows the implicit timeout of the driver instead of the explicit timeout set by the user

Currently, I am using Python in combination with Selenium WebDriver to conduct testing on a web-app that is based on Angular. Within the login helper subroutine, my goal is to verify the success of a login before proceeding with the remainder of the tests ...

Exploring the power of ElasticSearch alongside Mysql

As I plan the development of my next app, I am faced with the decision between using NoSQL or a Relational Database. This app will be built using ReactJS and ExpressJS. The data structure includes relational elements like videos with tags and users who li ...

Tips for moving and saving a file to a specific location before downloading it using Python and Selenium with the Chrome Webdriver

Recently, I started using the Selenium Chrome WebDriver. I have been navigating a webpage where I input my login details and then download a file in CSV format by clicking on a button (the file is saved directly to my downloads folder). However, I would p ...

I am interested in setting up a flickr gallery where clicking on an image will display a pop-up showing the image along with its relevant tags, title, and photo ID

Page´s photo Hello there, I am currently working on creating a Flickr API using JavaScript and HTML. My goal is to search for photos and display them in an HTML page, but I'm struggling with implementing a pop-up feature that includes the photo' ...

Guidance on loading JSON array information into highcharts using AngularJS

I am working on a project in Play Framework (play-java) where I need to display a bar graph using Highcharts. The Java API returns data in JSON format with a field called 'name' containing values like 'Data', 'Gadgets', ' ...

React - callbackFromApp function is executing only one time when clicked

Whenever I click a button within my child React module, it is meant to increment the timer and then pass back the timer in minutes and total seconds to the parent component where it will be stored as state. The issue I am facing is that when I click the b ...

What is the best way to reposition the mouse cursor in Selenium?

In my efforts to test a JavaScript web application with Selenium2 WebDriver C# API, I have encountered the need for performing hover actions on elements. To avoid code repetition, I created an extension method that handles this. public static void Hover(t ...

What is the most common method for creating a dropdown menu for a website's navigation?

Is there a common approach to creating an interactive drop-down navigation menu in the industry? I have searched on Google and found multiple methods, but as a student working on my first big web project, I am hoping to find a standard practice. I don&apo ...

Utilizing AJAX in Cordova to Generate Dynamic JavaScript Charts from JSON Data

Exploring the world of Cordova, I have delved into utilizing canvas Js for visualizing data in chart format. Following a helpful tutorial, I created a Json file and inserted the specified data as instructed, following each step diligently. The outcome matc ...

Filtering an array of JSONs in Vue.js using a separate array of JSONs

In my code, there are two arrays of JSONs: one named products and another called deletedProducts. The task is to filter out the products that are not present in the deletedProducts array. For instance: products = [ { id: 1, name: 'Box&apos ...

Retrieve a single value from a JavaScript array

There must be something simple I am missing here, as all the search results I found relate to looping over arrays, which is not what I want. My ajax call returns a response in the form of a straightforward array. When I use console.log(response); in the s ...