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

Present a pop-up notification box with a countdown of 30 seconds prior to the expiration of a session timeout in JSF

Our task is to create a timeout window that appears 30 seconds before the session expires. If the user remains inactive, they will be automatically redirected to the home page. We already have the maximum allowed duration of inactivity defined. I would l ...

Utilizing Ajax for Efficiently Updating a Singular Field within a Designated Object

How can I use Ajax to Update a Single Field in a Specific Object? I have a table in my postgres database with numerous records. I am interested in using a jquery Ajax request to update just one field in a particular object within that table. Is it possibl ...

Is it possible to save the video title as a variable using YTDL-core?

Is there a way to store the video title as a global variable in JavaScript? ytdl.getBasicInfo(videoURL, function(err, info) { console.log(info.title) }); I have been trying various methods but I am unable to successfully define a variable to hold the v ...

What is the best way to create subpages within a survey?

If I want to create a survey page on the web with multiple questions, but I am facing a challenge. I do not want to have several different pages and use a "Next Button" that links to another page. I am struggling to come up with ideas on how to implement ...

Exploring the World of AJAX with CodeIgniter

I've been on the hunt for a solid working example of using AJAX with Codeigniter, but most resources I've found are outdated. As an AJAX beginner, I'm struggling to find up-to-date tutorials. What I'm aiming for is an input form on a w ...

Using Selectpicker with Jquery .on('change') results in the change event being triggered twice in a row

While utilizing bootstrap-select selectpicker for <select> lists, I am encountering an issue where the on change event is being triggered twice. Here is an example of my select list: <select class="form-control selectpicker label-picker" ...

Encountering the error of receiving "$ undefined," despite making a reference to the library

I have included the JQuery library in the following way: <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js" type="text/javascript"></script> Despite trying to download the library and include it locally in my project, I ...

Searching for a name in JSON or array data using jQuery can be accomplished by utilizing various methods and functions available

Having trouble searching data from an array in jQuery. When I input Wayfarer as the value for the src_keyword variable, it returns relevant data. PROBLEM The issue arises when I input Wayfarer Bag as the value for the src_keyword variable. It returns em ...

Approach for fetching these JSON records

I am currently exploring ways to retrieve all entries within a JSON payload using JavaScript. Specifically, I am interested in finding the best method to extract all instances of "o4" in a specific order (-159, -257). How can this be achieved? { ...

Unlinking styles from the template in Vue.js

I have a unique situation where my template contains a <style> block that needs to be positioned near its corresponding div due to CMS restrictions. However, when I try to integrate Vue.js into the mix, it appears to strip out the style block and di ...

The function correctly identifies the image source without error

I possess a pair of images: <img id="img1" src="l1.jpg" usemap="#lb" height="400" border="0" width="300"> <img src="images.jpg" id="img2"> Next up is some JavaScript: function validateImages () { if (document.getElementById('img2&ap ...

The onChange function is not triggered when the dropdown menu consists of only one item

I am facing an issue with my dynamically populated dropdown menu. When the dropdown contains only one element, the onChange() function of my select tag does not work as expected. It functions perfectly fine when there are multiple elements present. How c ...

Submitting data from a JavaScript frontend to a PHP backend

I've exhausted all options in attempting to resolve this issue. The javascript code is designed to send a list of product IDs to a PHP page. When products are selected, the submit button should activate the submit function. function submit() { ...

Switching the visibility of rows in a table

Imagine this as my example table: <table> <tr> <td>a</td> <td>one</td> <td>two</td> </tr> <tr> <td>b</td> <td>three</td> <td>four</t ...

The Robot Class is experiencing issues with file uploads in Internet Explorer 11 when using Selenium WebDriver

I am facing an issue when trying to upload a file using selenium webdriver in IE11 with Java. The code I have is able to click on the Browse button, but it gets stuck without entering or pasting the file name into the newly opened window. It seems that the ...

What is the best way to generate bootstrap rows from this code in React JS?

In my current array of objects, I have twelve items: { data:[ { type:"tweets", id:"1", attributes:{ user_name:"AKyleAlex", tweet:"<a href="https://twitter.com/Javi" target="_blank"> ...

Why is there a false positive in the onChange event for the number type in React TypeScript?

I encountered an error on line 24 Argument of type 'string' is not assignable to parameter of type 'SetStateAction'.ts(2345) This issue occurred while working with TypeScript for a React experiment. const App: React.FC = () => ...

React-Leaflet continuously updates the map with the "MouseMove" event

I'm looking to implement a feature in my React app that displays the geographic coordinates as the mouse moves. However, I've noticed that using "Mousemove" causes the map to be continually redrawn with all objects each time, resulting in poor pe ...

Having trouble installing the @mui/x-data-grid package in a React project

npm install @mui/x-data-grid encounters a problem that throws an error message: npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: <a href="/cdn-cgi/l/email-protection" class="__cf_email__" dat ...

Adding default parameters in AngularJS Route-UI is a useful feature for setting up

Using angular UI-Router in my app, I've set up my base language as English. I have both English and Hebrew locals, and I want to avoid adding parameters to the URL if the language is English. For instance: Home English --> http://example.com/ Ho ...