What I'm trying to accomplish is for each element picked by xpath do some action. To be precise
var localizator = LocalizatorGenerators.SelectOptionLocator(labelName);
decimal totalElements = selenium.GetXpathCount((localizator));
for (int i = 1; i < totalElements + 1; i++)
{
if (selenium.IsElementPresent(string.Format("({0})[{1}]", localizator, i)))
selenium.Select(string.Format("({0})[{1}]", localizator, i), value);
}
The problem is with xpath probably since its not trivial.
//tr[not(contains(@style,'display: none;'))]/td/span[text()='{0}']/parent::*/following-sibling::*//select[not(contains(@disabled,'true'))]
If i would want to try to selenium.Select(localizator,value) it's working fine but only changes first dropdown selector.
From what i've researched problem might be with using open brackets() in selenium xpath. While trying to execute xpath in firefox firepath everything works fine.
Here is part of my html code.
<tr><td width="34%" valign="top" bgcolor="#ffffc7"><span>Podejmij decyzję</span><span></span></td><td width="66%" bgcolor="#ffffc7"><div>
<table cellspacing="0" border="1" style="border-collapse:collapse;" id="4162" rules="all" class="gridViewCtrl">
<tbody><tr>
<th scope="col">Produkt</th><th scope="col">Decyzja</th>
</tr><tr>
<td>Ekspres Linia</td><td><select id="ctl00_ContentPlaceHolder_4162_ctl02_DropID" name="ctl00$ContentPlaceHolder$4162$ctl02$DropID">
<option value="1"></option>
<option value="2">Pozytywna</option>
<option value="3">Negatywna</option>
</select><span style="display:none;" class="validation" id="ctl00_ContentPlaceHolder_4162_ctl02_ctl00">Wymagane</span></td>
</tr><tr>
<td>AgroEkspres</td><td><select id="ctl00_ContentPlaceHolder_4162_ctl03_DropID" name="ctl00$ContentPlaceHolder$4162$ctl03$DropID">
<option value="1"></option>
<option value="2">Pozytywna</option>
<option value="3">Negatywna</option>
</select><span style="display:none;" class="validation" id="ctl00_ContentPlaceHolder_4162_ctl03_ctl00">Wymagane</span></td>
</tr>
</tbody></table>
Also as u might imagine i must use xpath not id's. Thank you for all the help.
SOLUTION: Believe it or not i spent almoust 2 hours figuring this out while the solution was really simple. With brackets u just have to explicitely type xpath= in the locator.
Full solution
var localizator = LocalizatorGenerators.SelectOptionLocator(labelName);
var totalElements = selenium.GetXpathCount((localizator));
var anyMatched = false;
for (var i = 1; i <= totalElements; i++)
{
var loc = string.Format("xpath=({0})[{1}]", localizator, i);
var options = selenium.GetSelectOptions(loc);
foreach (var option in options)
{
if (option == value){ selenium.Select(loc, value); anyMatched = true}
}
}
if(!anyMatched) throw new Exception(string.Format("No matching value {0} for label {1}",value,labelName));