0

I have following XML

<div class="new_select">
  <select id="Schwarzkopf Live Hair Colour1" class="sf_input" name="id[8]">
       <option value="0">Select Schwarzkopf Live Hair Colour</option>
       <option disabled="" value="199">Black #1.0 </option>
</select>
</div>

And I want to save the attribute value id (Schwarzkopf Live Hair Colour1) for the the node 'select'

Can't remember the function for this. Help Please.

Amit
  • 21
  • 2

1 Answers1

0

If this were your entire XML file, then you could use this:

/div/select/@id

to access the id attribute of that select. If it's not, this would find that attribute:

//select/@id

but it would also find id attributes on all the other selects if there are any others. Is there a chance that there will be more than one select? Is there a way to uniquely single out this one?

JLRishe
  • 99,490
  • 19
  • 131
  • 169
  • You guessed rightly, it is not the only select. But I can uniquely identify this select. I am using ruby/capybara and trying to store this id. dropdown = browser.find(:xpath, "//div[@id='addtocart_modal']//select/@id"). But it is not working. I am getting this error message "The given selector //div[@id='addtocart_modal']//select/@id is either invalid or does not result in a WebElement. The following error occurred: InvalidSelectorError: The result of the xpath expression "//div[@id='addtocart_modal']//select/@id" is: [object Attr]. It should be an element. – Amit Jan 18 '13 at 03:28
  • The error suggests that you can only use find() to select an element, and not an attribute. From the comments on [this SO question](http://stackoverflow.com/questions/12437585/select-mixed-mode-content-in-capybara), it sounds like this is a limitation in the XPath support of a certain driver Capybara uses. The suggested workaround there is to use the selenium-webdriver or Nokogiri. – JLRishe Jan 18 '13 at 03:38