如何使用 watir-webdriver 选择下拉菜单项

mar*_*875 1 ruby automation watir webautomation watir-webdriver

我正在使用 watir-webdriver 来自动化和测试应用程序。在此过程中,我需要单击下拉菜单并选择一个值,但是 watir 似乎无法选择该项目。请帮忙?

我的代码:

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"
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

<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>
Run Code Online (Sandbox Code Playgroud)

我正在尝试选择网站要求的月份、年份和性别。谢谢你的帮助 :)

Ale*_*nko 5

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
Run Code Online (Sandbox Code Playgroud)