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

  • SEARCH
  • Home
  • 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 8566557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:40:53+00:00 2026-06-11T17:40:53+00:00

I am trying to migrate Java code from Selenium 1 (RC) to Selenium 2

  • 0

I am trying to migrate Java code from Selenium 1 (RC) to Selenium 2 (WebDriver) that looks something like this:

1:  selenium.click(someButton);
2:  selenium.waitForPageToLoad();
3:  if (!selenium.isElementPresent(errorMessageElement)) {
4:     Assert.fail("Test failed! No error msg should be displayed on page.");
5:  }

The critical part is line 3, which I tried to translate to Selenium 2 according to advice by Rostislav Matl :

3:  if (!driver.findElements(By.xpath(errorMessageElement)).size() > 0) {

Unfortunately, WebDriver waits for an entire timeout (in my case 60 seconds) to detect that the element really does not exist. Although this works, it introduces way too much time overhead…

Is there any way in Selenium 2 to time-efficiently check whether an element is present or absent on the HTML page that is currently displayed in the Web browser?

  • 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-11T17:40:54+00:00Added an answer on June 11, 2026 at 5:40 pm

    here is a two part answer

    1. The time overhead is right: As you would want to make sure that the element is really not rendered. That is, taking the page rendering time, AJAX elements etc in account. I understand that the error message would be displayed along with the page load, but timeout is useful in case you want to check presence (or absence) of ajax elements which get displayed with few milisecond delay.

    2. Hack to reduce wait overhead: You can nevertheless create a method to temporarily reset the implicit wait time like this

    public boolean isElementNotPresent(By by) {
        boolean flag = true;
        driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
        if (!driver.findElements(by).size() > 0) {
            flag = false;
        } 
        driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
        return flag;
    }
    

    and call this method where you want to check the absence, say for example the 3rd and 4th line would be

    if (!isElementNotPresent(By.xpath(xpathoferrorelement))) {
        Assert.fail("Test failed! No error msg should be displayed on page.");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are trying to migrate our system to WebDriver from Selenium 1. Thorough the
I am new to PHP trying to migrate from Java to PHP. This question
I have been trying to migrate a database from Sybase to MySQL. This is
I've a litle big problem with java heap memory I'm trying to migrate from
When i am trying to migrate the code from OL 3.3 to 4.9 i
I am trying to migrate my java application from JBoss 5.1 to JBoss 7.0.
I'm a Java programmer trying to migrate to C#, and this gotcha has me
Trying to migrate from MSSQL to MySQL. This Stored Proc is creating a temp
I'm trying to migrate Spring from XmlApplicationContext to AnnotationConfigApplicationContext (more info: Java-based container configuration
I'm currently trying to migrate a bit of legacy code from iPhone to Android.

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.