简体   繁体   中英

How can I select an drop down menu item with watir-webdriver

I'm using watir-webdriver to automate and test with an application. In the process I need to click on a drop down and select a value, however watir can't seem to select the item. Please help?

My code:

browser.text_field(:id => "user_username").set "#{username}"
browser.select_list(:id => 'user_date_of_birth_month').clear
puts browser.select_list(:id => 'user_date_of_birth_month').options
browser.select_list(:id => 'user_date_of_birth_month').select "9"

HTML:

 <label class="sc-font-light sc-text-light next-light-label" for="user_date_of_birth_month
2. When were you born?<span class="inline-help"><span class="content hidden">For information on why we ask for your date of birth, see <a href="http://help.soundcloud.com/customer/portal/articles/1481474-why-do-you-need-my-date-of-birth-" target="_blank">this help center article</a>.</span></span>

<div class="width_1_2"><select id="user_date_of_birth_month"name="user[date_of_birth][month]">
 <option value="">Month</option>
 <option value="1">January</option>
 <option value="2">February</option>
 <option value="3">March</option>
 <option value="4">April</option>
 <option value="5">May</option>
 <option value="6">June</option>
 <option value="7">July</option>
 <option value="8">August</option>
 <option value="9">September</option>
 <option value="10">October</option>
 <option value="11">November</option>
 <option value="12">December</option>
</select>
</div>

I'm trying to select a month, year and the gender the site asks for. Thanks for your help :)

browser.select_list(:id => 'user_date_of_birth_month').option(:value => '9').select
browser.select_list(:id => 'user_date_of_birth_month').option(:text => 'September').select

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM