Selecting a dropdown value in Selenium WebDriver

0 votes

I want to select a value from the drop down. The id=dropdownId and I am trying to select Last 52 weeks.

Html tag:

<select id=" dropdownId " 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>

M not able to click the drop down as I m getting an error: - 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 multiselect widget format

Apr 9, 2018 in Selenium by nsv999
• 5,050 points
883 views

1 answer to this question.

0 votes

Try to wrap your WebElement as shown below

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

After this 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 use

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

And to select its option say 'Programmer' you can do

dropdown.selectByVisibleText("Programmer ");

or

dropdown.selectByIndex(1);

or

 dropdown.selectByValue("prog");
answered Apr 9, 2018 by QueenBee
• 1,810 points

Related Questions In Selenium

0 votes
1 answer

How to Click a Link by href value in Selenium WebDriver?

Hi Ujjwal, you can use following code ...READ MORE

answered 5 days ago in Selenium by Abha
• 19,420 points
13 views
0 votes
1 answer

Double click a record in a grid using Selenium webdriver

Try Actions class to perform this Actions action ...READ MORE

answered Mar 29, 2018 in Selenium by Damon Salvatore
• 5,510 points
892 views
0 votes
1 answer
0 votes
1 answer

Select an item from a dropdown list using Selenium WebDriver

Use this then it will work - new ...READ MORE

answered Apr 9, 2018 in Selenium by Vardy
• 2,250 points
1,736 views
0 votes
1 answer
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,050 points
409 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
767 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
404 views