0

Given the following code.

<ul class="search-fields clearfix">
<li class="charter-type-search clearfix">
<li class="destination-search where clearfix">
<li class="departure-search when clearfix">
  <div class="icon-heading">
  <div class="icon-search holiday-search-fields form-type-select form-item-date">
  <select id="edit-date" class="form-select ajax-processed" name="date">
    <option selected="selected" value="">Anytime</option>
    <option value="2015-12">December 2015 (25)</option>
    <option value="2016-01">January 2016 (26)</option>
    <option value="2016-02">February 2016 (29)</option>
    <option value="2016-03">March 2016 (30)</option>
    <option value="2016-04">April 2016 (38)</option>
    <option value="2016-05">May 2016 (37)</option>
    <option value="2016-06">June 2016 (40)</option>
    <option value="2016-07">July 2016 (39)</option>
    <option value="2016-08">August 2016 (37)</option>
    <option value="2016-09">September 2016 (33)</option>
    <option value="2016-10">October 2016 (33)</option>
    <option value="2016-11">November 2016 (28)</option>
    <option value="2016-12">December 2016 (25)</option>
    <option value="2017-01">January 2017 (21)</option>
    <option value="2017-02">February 2017 (21)</option>
    <option value="2017-03">March 2017 (21)</option>
    <option value="2017-04">April 2017 (27)</option>
    <option value="2017-05">May 2017 (27)</option>
    <option value="2017-06">June 2017 (29)</option>
  </select>

I am using the following to retrieve a random date

all_options = b.select_list(id: "edit-date").options

b.select_list(id: "edit-date").option(index: rand(all_options.size)).select

if I wanted to remove the first 5 elements from this so (Dec15-April16) then randomly select the rest how can I do this? I am using .drop(5) but it still selects some of these dates.

1 Answer 1

2

For reference, the typical way to select from a list is by direct string:

b.select(id: 'edit-date').select('May 2017 (29)')

or regular expression

b.select(id: 'edit-date').select(/May 2017/)

All that select method is doing is locating, verifying & clicking on the element. The first two are already accomplished when you get the options list, so all you need to do from there is the click:

b.select(id: 'edit-date').options.drop(5).sample.click
2
  • Thank you so much! couldn't understand why drop(5) wasn't working.
    – rubytester
    Dec 23, 2015 at 20:17
  • OP: you should accept this answer if it solved your issue.
    – orde
    Dec 23, 2015 at 22:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.