Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to click a button without id using FluentAutomation SeleniumWebDriver?
    primarykey
    data
    text
    <p>I am using FluentAutomation library that wraps Selenium Web driver calls so the site can be navigated in a more behavioral manner.</p> <p>As long as elements have id or other distinct properties, it works straightforward:</p> <pre><code> I.Open(Site.BaseUrl); I.WaitUntil(() =&gt; I.Expect.Exists("#name-search")); I.Click("#applicationHost a"); </code></pre> <p>But I need the driver to click on the buttons identified with the following XPath expressions:</p> <pre><code>//div[@id='questions']/div/div/div[4]/label/span[2] //div[@id='questions']/div/div/div[2]/label/span[2] </code></pre> <p>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?</p> <p>UPDATE: Here's HTML extract from page inspector.</p> <pre><code>&lt;div class="small-12 large-10 columns large-centered" data-bind="foreach: currentQuestion.alternatives"&gt; &lt;div class="valg"&gt; &lt;label data-bind="attr: { for: 'radio-' + $index() }" for="radio-0"&gt; &lt;input type="radio" name="radio-question-40" data-bind="attr: { for: 'radio-' + $index() }, value: value" class="hidden" for="radio-0" value="1"&gt; &lt;span class="enighet" data-bind="text: ($index() + 1)"&gt;1&lt;/span&gt; &lt;span class="custom radio" data-bind="click: $parent.pickAnswer, css: { checked: $data.selected }"&gt;&lt;/span&gt; &lt;span class="enighet" data-bind="text: text"&gt;Text for option 1&lt;/span&gt; &lt;/label&gt; &lt;/div&gt; &lt;div class="valg"&gt; &lt;label data-bind="attr: { for: 'radio-' + $index() }" for="radio-1"&gt; &lt;input type="radio" name="radio-question-40" data-bind="attr: { for: 'radio-' + $index() }, value: value" class="hidden" for="radio-1" value="2"&gt; &lt;span class="enighet" data-bind="text: ($index() + 1)"&gt;2&lt;/span&gt; &lt;span class="custom radio" data-bind="click: $parent.pickAnswer, css: { checked: $data.selected }"&gt;&lt;/span&gt; &lt;span class="enighet" data-bind="text: text"&gt;Text for option 2&lt;/span&gt; &lt;/label&gt; &lt;/div&gt; &lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload