Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Following code works for selecting the last item from dropdown using Selenium 2.28 driver on Firefox and IE. Not working with Selenium Web Driver 2.40. I can see the dropdown opening but it is not responding selecting the option by using selectByIndex. How do I make it work? I am testing on Firefox 28 and IE8 on Windows 7.

WebElement dropDown = WebDriver.findElement(By.css("select name='tblCampaigns_length']"));
Select select = new Select(dropDown);
share|improve this question
are you getting any exceptions or other errors? Where is it failing at? – Dan Snell Apr 11 '14 at 15:53

try the following: c#

IWebElement dropDown = WebDriver.findElement(By.css("select name='tblCampaigns_length']"));
SelectElement select = new SelectElement(dropDown);
select.selectByIndex(select.Options.Count - 1);

The .Options retruns a list of options that then inherits the .Count in being a list. This will return the exact number of option elements that belong to the SelectElement object. It is 1 incremented as a count instead of 0 and therefore the -1 is added to sync up the correct index selection to the last one in the list.

share|improve this answer
Could you add some explanation for why this would work for the OP? We prefer answers to have more context than just the code. – Kate Paulk Aug 8 '14 at 10:44
This appears to literally be the c# version of the java code in the OP. – Yamikuronue May 6 '15 at 17:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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