The list contains values that start with "Comm"+String. So "Comm" is common in front of every value in the dropdown list. I want to pick a random string from the list which starts with "Comm" I read the element using
var selectList = driver.FindElement(GroupDropdown_1); selectList.FindElement(By.XPath(string.Format("//option[starts-with(text(),'{0}')]", "Comm"))).Click();
But it always pick by default the first occurrence in the dropdown list list. The HTML code is
<div id="RPaffgroups" name="RPaffgroups" style="display:inline;"><select name="groupid">
<option value="0">Comm Group: No Member Commission Group [ 52 mbrs]</option>
<option value="106">Aff Group: Retail - Affiliates 2018 [ 46 mbrs]</option>
<option value="106">Aff Group: Merchandise - Affiliates 2002 [ 433 mbrs]</option>
<option value="-1" selected="">Comm Group: Default Commission Group [ 52 mbrs]</option>
<option value="22" selected="">Comm Group: 0 Comm Group [ 52 mbrs]</option>
</select> <input type="checkbox" id="cbShowHiddenGroups" border="0" onclick="ToggleGroup('groupid',this);">Show hidden groups</div>
As seen above it always pick the first occurrence of the string starts with "Comm" which in the above case is Comm Group: No Member Commission Group [ 52 mbrs]