0

I am writing scripts in Ruby that supports Capybara. I will have to select a value from a dropdown list box and I am using "xpath" to find the element and make the selection.

The code is given below:

<select class="sortOrder fsm textCatalogTitleBlack" style="width: 150px;">
                                    <option value="/all-products/?sort=popularity&dir=desc"> Sản phẩm ưa chuộng </option>
                                    <option value="/all-products/?sort=name&dir=asc"> Tên </option>
                                    <option selected="selected" value="/all-products/?sort=price&dir=asc"> Giá  </option>
                                    <option value="/all-products/?sort=brand&dir=asc"> Thương hiệu </option>
                                    <option value="/all-products/?sort=latest arrival&dir=desc"> Mới nhất </option>
                                    <option value="/all-products/?sort=discount&dir=desc"> Giảm giá </option>
                            </select>

I will need to select "Giá" from the above list-box.

I have written the code as

 find(:xpath, "//select[@class='sortOrder.fsm.textCatalogTitleBlack']/option[@text=' Giá  ']").click

Result:

Unable to find xpath "//select[@class='sortOrder.fsm.textCatalogTitleBlack']/option[@text=' Giá  ']" (Capybara::ElementNotFound)

Please help. Is there any problem with the syntax?

Phrogz
  • 296,393
  • 112
  • 651
  • 745
  • Look at thin question: http://stackoverflow.com/questions/6729786/how-to-select-date-from-a-select-box-using-capybara-in-rails-3 – Evgeniy Shurmin May 22 '13 at 12:04

1 Answers1

0

The class attribute in your HTML is space delimited, but you have made it period-delimited in your XPath expression. XPath has no special awareness of class attributes, and does not use CSS syntax for them.

Switch to using spaces to match the value exactly, or else match only a particular part of the attribute.

Community
  • 1
  • 1
Phrogz
  • 296,393
  • 112
  • 651
  • 745