Intellipaat Back

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

I am new to selenium, currently am working on selenium webdriver I want to select a value from the drop-down. The id=periodId and the option are many in that I am trying to select the last 52 weeks.

Here is the Html tag:

<select id="periodId" name="period" style="display: none;">

    <option value="l4w">Last 4 Weeks</option>

    <option value="l52w">Last 52 Weeks</option>

    <option value="daterange">Date Range</option>

    <option value="weekrange">Week Range</option>

    <option selected="" value="monthrange">Month Range</option>

    <option value="yeartodate">Year To Date</option>

</select>

Please suggest me some ways to click the dropdown.

I tried with the above example lines but am getting error such as Element is not currently visible and so may not be interacted with Command duration or timeout: 32 milliseconds the drop-downs values are the jquery multi-select widget format

1 Answer

0 votes
by (62.9k points)

Just wrap your WebElement into select Object as shown below

Select dropdown = new Select(driver.findElement(By.id("identifier")));

Once this is done you can select the required value in 3 ways. Consider an HTML file like this

<html>

<body>

<select id = "designation">

<option value = "MD">MD</option>

<option value = "prog"> Programmer </option>

<option value = "CEO"> CEO </option>

</option>

</select>

<body>

</html>

Now to identify dropdown do

Select dropdown = new Select(driver.findElement(By.id("designation")));

To select its option say 'Programmer' you'll be able to do

dropdown.selectByVisibleText("Programmer ");

or

dropdown.selectByIndex(1);

or

dropdown.selectByValue("prog");

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 online training

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...