selenium webdriver - How to click a button without id using FluentAutomation SeleniumWebDriver? -
i using fluentautomation library wraps selenium web driver calls site can navigated in more behavioral manner.
as long elements have id or other distinct properties, works straightforward:
i.open(site.baseurl); i.waituntil(() => i.expect.exists("#name-search")); i.click("#applicationhost a");
but need driver click on buttons identified following xpath expressions:
//div[@id='questions']/div/div/div[4]/label/span[2] //div[@id='questions']/div/div/div[2]/label/span[2]
etc. @ least xpath returned selenium ide recorder. don't seem able find right way of referencing these buttons. see, difference index of 1 of divs (div[4], div[2]). there common convention refer elements such xpath?
update: here's html extract 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 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 option 2</span> </label> </div> </div>
so can suggest xpath :
btn 1 : "//div[@class='valg'][position() = 0]/label/span[2]"
btn 2 : "//div[@class='valg'][position() = 1]/label/span[2]"
or in css selector
btn 1 : "div.valg:nth-child(1) label span.enighet"
btn 2 : "div.valg:nth-child(2) label span.enighet"
but see have more div you've show. tell me what's up.