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 8656387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:15:48+00:00 2026-06-12T15:15:48+00:00

I’m writing Java Selenium tests for listviews, specifically ones to validate and then select

  • 0

I’m writing Java Selenium tests for listviews, specifically ones to validate and then select an item from a listview.

It’s driving me crazy, though, as the tests will run fine half the time, but the other half they’ll give StaleElementReference or similar errors, often occuring at different stages each time. This is when running them under identical conditions.

I re-assign the WebElement variables each time the listview page changes as I gathered this might be the issue, but it still happens. I then thought it might be to do with needing to wait for the page to fully load but I’m not entirely sure how to make use of things like WebDriverWait that I’ve seen some others suggesting.
I do however know that our existing base page object class already includes something for waiting, so I think this may already be covered:

    public abstract class PageObject {

protected WebDriver driver;
protected WebDriverWait wait;
    ...
    public PageObject(WebDriver driver, String relativePath) {
            ...
            this.driver = driver;
            this.wait = new WebDriverWait(driver, 8);
            ...

Is that enough, or do I need a more specific form of ‘wait’ for this problem?

Aside from that, can anybody think of any possible common issues that might be causing this?

Thanks a lot

  • 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-12T15:15:49+00:00Added an answer on June 12, 2026 at 3:15 pm

    heh, come across with similar issue. The matter is when you got a lot of AJAX on the page, the best way (imho) to handle it and the wait i like most is fluentWait()

     public WebElement fluentWait(final By locator){
            Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
                    .withTimeout(30, TimeUnit.SECONDS)
                    .pollingEvery(1, TimeUnit.SECONDS)
                    .ignoring(NoSuchElementException.class);
    
            WebElement foo = wait.until(
                    new Function<WebDriver, WebElement>() {
                        public WebElement apply(WebDriver driver) {
                            return driver.findElement(locator);
                        }
                    }
            );
            return  foo;              
         };
    

    So you actually need to find the locator of web element (xpath, or css selector) and to pass it to fluent wait. And fluent wait, in turn, returns you found web element.
    From the documentation:
    An implementation of the Wait interface that may have its timeout and polling interval configured on the fly.
    Each FluentWait instance defines the maximum amount of time to wait for a condition, as well as the frequency with which to check the condition. Furthermore, the user may configure the wait to ignore specific types of exceptions whilst waiting, such as NoSuchElementExceptions when searching for an element on the page.

    usage:

    String xPathElement =".....blablabla...";
    WebElement neededElement =fluentWait(By.xpath(xPathElement));
     neededElement.click();
    //neededElement.getText().trim();
    

    you can get more info on it here

    The issue causing such kind of problem can be (from my experience ) of two types:
    1) first one

    you interact with an element causing page rendering or some else ‘slow’ operations. Selenium tests keep on going but the page actually not rendered >> staleElement.

    2) second one.
    you interact with one element. then you interact with another causing a lot of AJAX (not complete page reload, and first element refresh). and instantly you return back to the previous one (wanna e.g. getText or click)>>staleElement.

    So I always use fluent wait. It is comfortable from the point you can set up arbitratry exceptions ignoring.
    Hope this works for you.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Specifically, suppose I start with the string string =hello \'i am \' me And
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to select an H1 element which is the second-child in its group
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from

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.