I'm using C# in Visual Studio Community 2017, Selenium.Firefox.Webdriver v0.16.1, Selenium.WebDriver v3.4.0.
I am extracting text from a series of drop downs and in doing so need to add 1 to an int representing the index as selecting one dropdown populates the next one with different content depending on the model selected.
I have already extracted all values and stored in a list removing the first value of 'please Select'.
I've used:
selectModel.SelectByIndex(ModelIndex+1);
But intermittently get the OpenQA.Selenium.NoSuchElementException: 'Cannot locate option with index: 1' on the second dropdown and always on the third.
If I replace with:
selectModel.SelectByIndex(1);
The code I've written works fine, but I'm wanting to increment through the index until it is exhausted.
I am incrementing and decrementing the index value now but I don't think it is the best way of doing things:
var modelDropDown = driver.FindElement(By.Name("Model"));
var selectModel = new SelectElement(modelDropDown);
ModelIndex++;
selectModel.SelectByIndex(ModelIndex);
ModelIndex--;
HTML example of the second dropdown:
<select name="Model" id="Model-select" class="form-control asset-option-select ng-pristine ng-not-empty ng-valid ng-valid-required ng-touched" required="" ng-options="option.label for option in dropdown.options track by option.value" ng-model="dropdown.selected" ng-change="select_option(dropdown)" ng-disabled="model.is_locked || dropdown.options.length === 0">
<option value="" selected="selected" disabled="disabled" class="" hidden="">Please Select</option>
<option label="Cherokee" value="Cherokee">Cherokee</option>
<option label="Grand Cherokee" value="Grand Cherokee">Grand Cherokee</option>
<option label="Renegade" value="Renegade">Renegade</option>
<option label="Wrangler" value="Wrangler">Wrangler</option>
<option label="Pre-current Cherokee" value="Pre-current Cherokee">Pre-current Cherokee</option>
</select>
Maybe I'm going about the whole thing the wrong way but that's why I'm asking here, I'm mainly wanting to know why I am getting the error with:
SelectByIndex(ModelIndex+1)