Select Option in a Select using Partial Text

If you ever come across the need to select an option in a drop down list when you only have some of the text here is how you can select a particular option oin a drop down list using a partial text selector. In this example the drop down list would be populated with strings formatted as follows: FirstName LastName – Address. eg “John Smith – 1001 Main St”. For the test we only have the person’s name available to us.

IWebElement ddlList = driver.FindElement(By.Id("ddlList"));
string strName = "John Smith";

ddlList.FindElement(By.XPath(string.Format("./option[starts-with(text(), '{0}')]", strName))).Click();

Advertisements

WebDriver 2.47 released

The latest version of Selenium WebDriver, 2.47.0 has been released. You can get the direct link for the downloads for the Selenium Server and the Java and C# bindings below. The changelogs for each, as well as other language bindings can be found on the Selenium Downloads page

Downloads: