I am using FluentAutomation library that wraps Selenium Web driver calls so the site can be navigated in a more behavioral manner.
As long as elements have id or other distinct properties, it works straightforward:
I.Open(Site.BaseUrl);
I.WaitUntil(() => I.Expect.Exists("#name-search"));
I.Click("#applicationHost a");
But I need the driver to click on the buttons identified with the following XPath expressions:
//div[@id='questions']/div/div/div[4]/label/span[2]
//div[@id='questions']/div/div/div[2]/label/span[2]
etc. At least this is the XPath returned by Selenium IDE recorder. But I don't seem to be able to find right way of referencing these buttons. As you see, the only difference is the index of one of the divs (div[4], div[2]). Is there a common convention to refer to elements with such XPath?
UPDATE: Here's HTML extract from page inspector.
<div class="small-12 large-10 columns large-centered" data-bind="foreach: currentQuestion.alternatives">
<div class="valg">
<label data-bind="attr: { for: 'radio-' + $index() }" for="radio-0">
<input type="radio" name="radio-question-40" data-bind="attr: { for: 'radio-' + $index() }, value: value" class="hidden" for="radio-0" value="1">
<span class="enighet" data-bind="text: ($index() + 1)">1</span>
<span class="custom radio" data-bind="click: $parent.pickAnswer, css: { checked: $data.selected }"></span>
<span class="enighet" data-bind="text: text">Text for option 1</span>
</label>
</div>
<div class="valg">
<label data-bind="attr: { for: 'radio-' + $index() }" for="radio-1">
<input type="radio" name="radio-question-40" data-bind="attr: { for: 'radio-' + $index() }, value: value" class="hidden" for="radio-1" value="2">
<span class="enighet" data-bind="text: ($index() + 1)">2</span>
<span class="custom radio" data-bind="click: $parent.pickAnswer, css: { checked: $data.selected }"></span>
<span class="enighet" data-bind="text: text">Text for option 2</span>
</label>
</div>
</div>