Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

I am using Selenium for the first time and am overwhelmed by the options. I am using the IDE in Firefox.

When my page loads, it subsequently fetches values via a JSONP request, with which it populates options in a select.

How do I get Selenium to wait for a certain option in the select to be present before proceeding?

1 Answer

0 votes
by (62.9k points)

I have had a similar problem where the options within drop-down were fetched from a third-party service, which sometimes was a slower operation.

 Select select = new Select(driver.findElement(cssSelector("cssSelectorOfSelectBox")));    

waitUnitlSelectOptionsPopulated(select)

here is the definition for waitUnitlSelectOptionsPopulated

 

private void waitUntilSelectOptionsPopulated(final Select select) {

            new FluentWait<WebDriver>(driver)

                    .withTimeout(60, TimeUnit.SECONDS)

                    .pollingEvery(10, TimeUnit.MILLISECONDS)

                    .until(new Predicate<WebDriver>() {

                        public boolean apply(WebDriver d) {

                            return (select.getOptions().size() > 1);

                        }

                    });

        }

Note: A check of select.getOptions().size() >1 was needed in our case as we had one static option always displayed.

If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, check out Intellipaat’s Selenium training!

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...