Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8272357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:06:15+00:00 2026-06-08T07:06:15+00:00

How would you go about checking to see if a particular WebElement has been

  • 0

How would you go about checking to see if a particular WebElement has been updated?

I have a test that performs a form save and then the UI returns a success/error message.

I am doing a series of saves and I need to test and see if the message is what is expected.

Selenium goes so fast that the browser does not have a chance to catch up.

This is the code that I have for testing for an error message (There is an equivalent success message function as well)

    public void assertErrorMessage(String errorMsg) {

    // set the wait time a bit so the page can load.
    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    List<WebElement> results = driver.findElements(By.xpath("//div[@id='lift__noticesContainer__']/descendant::*"));
    boolean success = false;
    String message = "";
    for (WebElement result : results) {

        String id = result.getAttribute("id");
        if (id.contains("___error")) {
            success = true;
        }
        if (result.getTagName().equals("li")) {
            message += result.getText().trim();
        }
    }
    Assert.assertTrue(success, "No error message generated");
    Assert.assertTrue(message.equals(errorMsg), "Expecting message: \"" + errorMsg + "\" but got \"" + message + "\"");

}

As this is written, this looks for the presence of a particular <div> and checks to see if contains certain attributes. If it does, get the message.

The thing is, this will always be true and hence my tests are failing since the message is different than the previous one, but the UI hasn’t caught up to where selenium is.

My solution so far to force a Thread.sleep(2000) to just pause a bit to allow for the UI to catch up. I know that it is frowned upon to use Thread.sleep().

i.e. (pseudo-code)

page.setField("value");
page.save();
Thread.sleep(2000);
page.assertErrorMessage("Error message");

Is there any way let me check to see if a WebElement has been updated? If so, I could use the Selenium waits to test for that.

Or perhaps someone else has a suggestion for how to do this?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T07:06:17+00:00Added an answer on June 8, 2026 at 7:06 am

    If the result displayed keeps getting every time you perform page.save().

    The best way to make sure that your code waits for the browser to update the message is by using the WebDriverWait object.

    A simple example would be –

    new WebDriverWait(driver, 10).until(ExpectedConditions.textToBePresentInElement(By.xpath("xpath"), "message"));
    

    You can check if that particular element has the message you are looking for. If that message is not present even after 10 seconds then a TimedOutException will be thrown.

    You can check out more variations on the ExpectedConditions as suitable in your situation. Hope this helps you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would I go about checking if and include or a require has an
I was just wondering how would I go about checking to see if, for
How would one go about checking to see if a method exists for a
I was wondering how I would go about checking to see if a table
How would I go about checking if a domain name is registered? I was
I would like to know how I would go about altering the HTML that
Anyone have any idea how I would go about converting a timestamp in milliseconds
I have about 30 clickable divs on my page so I figured I would
How would I go about implementing a thread that runs throughout the application. I
I am soon to join a PHP project that has been developed over the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.