【问题标题】:Unable to select a value from drop down in cucumber capybara无法从黄瓜水豚的下拉菜单中选择一个值
【发布时间】:2012-05-12 01:31:03
【问题描述】:

我正在使用 cucumber 和 capybara 来自动化 Web 应用程序。我必须从下拉列表中选择一个值,但很多时候我都收到类似的错误; “错误的参数类型字符串(预期的数组)(TypeError)”

我尝试过: 1.

second_option_xpath = ".//*[@id='selecttype']/option[2]"  
second_option = find(:xpath, second_option_xpath).text
select(second_option, :from => 'selecttype')

2.

select "Selenium Core", :from => 'selecttype'

3.

page.find_and_select_option("selecttype", 2)

4.

select( "selecttype", {"Selenium Core" => 2})

页面来源类似于:

<select id="selecttype"> 
<option value="Selenium IDE">Selenium IDE</option> 
<option value="Selenium Code">Selenium Core</option> 
<option value="Selenium RC">Selenium RC</option> 
<option value="Selenium Grid">Selenium Grid</option> 
</select>"

请指出我哪里做错了?

谢谢

【问题讨论】:

  • 我尝试了您的第二个解决方案,其页面包含您提供的源代码,但它按预期选择了该选项(即无法重现您的问题)。页面上是否还有其他内容导致冲突?你用的是什么版本的水豚?
  • 您的第二个选项 - “Selenium Code”与文本“Selenium Core”不匹配,这可能会导致您的不匹配

标签: cucumber capybara


【解决方案1】:

你试过了吗

page.select('Selenium Core', :from => 'selecttype')

【讨论】:

  • 它对我有用。除了@Atin 没有接受答案,这是正确的答案。
【解决方案2】:

正如 RobertH 建议的那样,您应该使用 page.select 之类的东西,其中 page 是 Capybara::Session 实例。

当您在代码中调用 select 时,您正在调用 Kernel 模块的一个方法,该方法混合在基本 Object 类中,每个类都继承自该类。

这个方法需要4个参数,其中3个是IO对象数组;这就是它抱怨错误论点的原因。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-30
    • 2012-07-06
    相关资源
    最近更新 更多