1

对于这样的 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)

当我不使用索引值时它工作正常。

4

2 回答 2

0

If I understood the question the problem is that this works:

select_list(:select_lang, :class => "intl_drop")

but this does not work:

select_list(:select_lang, :class => "intl_drop", :index => 1)

The problem could be that there is only one select list with class intl_drop.

:index => 1 will select the second element. :index => 0 will select the first one.

于 2013-04-19T07:30:32.470 回答
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

希望这可以帮助。

于 2013-12-06T21:08:00.597 回答