对于这样的HTML:
<select class="intl_drop" name="select_locale">
<option value="0">- Select One -</option>
<option value="1">United States - English</option>
<option value="2">United States - Español</option>
<option value="3">Canada - English</option>
当我尝试使用
选择选项时select_list(:select_lang, :class => "intl_drop", :index => 1)
我得到错误信息
Unable to locate element{"method":"xpath","selector":".//select[@class=' intl_drop'][2]"} (Selenium::WebDriver::Error::NoSuchElementError)
当我不使用索引值时,它可以正常工作。
如果我理解了这个问题,问题是这是有效的:
select_list(:select_lang, :class => "intl_drop")
,但这不起作用:
select_list(:select_lang, :class => "intl_drop", :index => 1)
问题可能是class
intl_drop
只有一个选择列表。
:index => 1
将选择第二个元素。:index => 0
将选择第一个
为什么不呢:
select_list(:select_lang, name="select_locale")
和基于你的语句,你想选择对象的索引或值?
select_lang_element.select_value(1)
或
select_lang_element[1].click
这些都适合我。
是一个被弃用的冗长的方式select_lang_element.option[:value, '1'].click