- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to wait for options in a select to be populated in Selenium?
We can wait for options in a select tag to be populated with Selenium. This can be done with the explicit wait concept in synchronization. The explicit wait is designed on the expected condition for an element.
To wait for the options, we shall verify if presenceOfNestedElementsLocatedBy is available within the explicit wait time. We shall implement the entire verification within the try catch block.
Let us see if the options are available for selection in the Continents dropdown. The ExpectedCondition along with WebDriverWait is used for explicit wait.
HTML code of the select dropdown.
Example
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.support.ui.Select; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; public class SelectOptWait{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get("https://www.tutorialspoint.com/selenium/selenium_automation_practice.htm"); //expected condition presenceOfNestedElementsLocatedBy on options WebDriverWait w = new WebDriverWait(driver,3); try { w.until(ExpectedConditions .presenceOfNestedElementsLocatedBy (By.xpath("//select[@name='continents']"), By.tagName("option"))); // identify dropdown WebElement l = driver.findElement(By.xpath("//select[@name='continents']")); // select option by Select class Select s = new Select(l); // selectByVisibleText to choose an option s.selectByVisibleText("Africa"); } catch(Exception e) { System.out.println("Options not available"); } driver.quit(); } }
- Related Articles
- How to wait for iFrames to load completely in Selenium webdriver?
- How to get Selenium to wait for ajax response?
- How to verify if we can select multiple options in a static dropdown in Selenium?
- Best practice to wait for a change with Selenium Webdriver?
- How do you make Selenium 2.0 wait for the page to load?
- How to wait until an element is present in Selenium?
- Wait for complex page with JavaScript to load using Selenium.
- How to wait for a goroutine to finish in Golang?
- How to select multiple options in a dropdown list with JavaScript?
- How to wait until an element no longer exists in Selenium?
- Wait for an Ajax call to complete with Selenium 2 WebDriver.
- How to use select list in selenium?
- How to get all the options in the dropdown in Selenium?
- How to select an option in a static dropdown in Selenium?
- Selenium with C Sharp - How to perform Explicit Wait method?

Advertisements