0

我正在尝试从我的选择字段中选择一个值:

<select class="form-control select required chosen-select" name="shopping_cart[kind]" id="shopping_cart_kind" style="display: none;"> 
     <option value="">Selecione</option>
     <option value="pdc">PDC</option>
     <option value="normal">Cotação Normal</option>
     <option value="emergency">Cotação Emergencial</option>
     <option value="contract">Cotação para Contrato</option>
     <option value="price_research">Pesquisa de Preço</option>
     <option value="legal_purchase">Compra Judicial</option>
     <option value="bidding_exemption">Dispensa de Licitação</option>
     <option value="scheduled_delivery">Cotação para entrega programada</option></select>

在我的代码中,我试图设置第二个选项:

@type = @browser.select_list(id: "shopping_cart_kind")
@type.select 'PDC'

我收到了这个错误:

timed out after 30 seconds, waiting for {:id=>"shopping_cart_kind", :tag_name=>"select"} to become present (Watir::Wait::TimeoutError)

我尝试了以下替代方法,但它们不起作用:

  • 通过javascript单击元素:

    @browser.execute_script("返回参数[0].click();", browser.link(:id => 'shopping_cart_kind')

  • 按索引选择:

    @browser.select_list(id: "shopping_cart_kind", index: 1).select ("PDC") @browser.select_list(id: "shopping_cart_kind").option[1].select

没有任何效果!

4

1 回答 1

0

你能试试这个代码,让我知道它是否有效吗?

@type = @browser.select_list(id: "shopping_cart_kind")
@type.option(text: 'PDC').select
于 2018-12-28T14:06:41.723 回答