What do I need to do if drop down take time to populate 1st element from drop down list?

enter image description here

Select Cdropdown = new Select(driver.findElement(By.xpath("//select[@id='ClientId']")));


Select Edropdown = new Select(driver.findElement(By.xpath("//select[@id='EnvironmentId']")));

For loading the drop down it should take the time I have used- Thread.sleep(3000); but still the element is not found. What should I do in such a case?

  • 1
    Is it works for first dropdown? or getting issue with both?
    – Bharat Mane
    Commented May 13, 2016 at 12:37
  • Its work for first dropdown for second its fail
    – Mahesh
    Commented May 13, 2016 at 12:57
  • What error are you getting? Commented May 14, 2016 at 3:06
  • Error which got after ran the code: Cannot locate element with text: centralpen-prod-m-01 For documentation on this error, please visit: seleniumhq.org/exceptions/no_such_element.html
    – Mahesh
    Commented May 16, 2016 at 9:37

4 Answers 4


Do you think that time is the problem here?

If so try to increase the time you are providing in Thread.sleep(); and see it that works out for you.

If its not the time, then did you try to find out what the problem is? Are you getting any error?

  • 1
    While that's one thing to consider trying, we may want to ask ourselves if Thread.sleep() is what we want at all - do we want to rely on a certain amount of time if time itself isn't a requirement?
    – corsiKa
    Commented May 13, 2016 at 16:58
  • 1
    Increase sleep time? And this is most upvoted answer? Will THIS be representative of the future quality of the answers here? Sad day... Commented May 16, 2016 at 14:40

adding Thread.sleep(3000) is not a good way to handle synchronization, rather use implicit wait.

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

Implicit wait allows your browser to wait until element is visible or until time set by you, whichever is earlier.



Select Cdropdown = new Select(driver.findElement(By.xpath("//select[@id='ClientId']")));

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

Select Edropdown = new Select(driver.findElement(By.xpath("//select[@id='EnvironmentId']")));
//check your index, starting from 0 which item you have to select & add corresponding index of that.  

You may try with same method-selectByVisibleText as like 1st dropdown

3: Otherwise You may try with explicitly wait-

 //Selecting value from 2nd drop down using visible text

    Select mydrpdwn = new Select(driver.findElement(By.id("EnvironmentId")));
    mydrpdwn.selectByVisibleText("add element in dropdown");

    WebDriverWait wait = new WebDriverWait(driver, 15);
  • I try both way but still the script is not work. I think its application issue for populating the drop down
    – Mahesh
    Commented May 16, 2016 at 13:31

try following code:

WebDriverWait wait;
wait = new WebDriverWait(driver, Duration.ofSeconds(15));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.