Rajarshi
Rajarshi

Reputation: 381

Ambiguous error in xpath [last()] method

In a custom step in cucumber, I wrote this:

find(:xpath ,"//ul//input[@placeholder = 'Enter Something'][last()]").set(value)  

And Im getting Regexp ambiguous match error:It is getting both the elements. How can I get this element using xpath(or maybe even css) in cucumber??

I'm using cucumber-1.2.1 and capybara-2.0.3

(Please note:every attribute in the above two input fields are same)

HTML:

<ul class = "someclass">
  <li>
   <div>
     <a></a>
       <input></input>
       <input placeholder = "Enter Something"></input>
   </div>
   </li>   
 <li>
   <div>
     <a></a>
       <input></input>
       <input placeholder = "Enter Something"> // This is the element I want 
       </input>
   </div>
   </li>   
 </ul>

Upvotes: 1

Views: 266

Answers (1)

StuartLC
StuartLC

Reputation: 107277

You'll need an extra set of parenthesis in your xpath:

"(//ul//input[@placeholder = 'Enter Something'])[last()]"

Upvotes: 1

Related Questions