Unable to select value from lowering capybara cucumber

I am using cucumber with capybara to automate a web application. I have to select a value from the drop-down list, but many times I get an error, for example; "invalid String argument type (expected array) (TypeError)"

I tried: 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})

PAGE SOURCE SOMETHING LIKE:

<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>"

Please suggest where I am doing wrong?

thank

+3
source share
2 answers

You tried

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

As RobertH suggests, you should use something like page.select, where the page is an instance of Capybara :: Session.

When you call select in your code, you call the Kernel module method, which is mixed in the base class Object, which each class inherits from.

4 , 3 IO; , .

0

All Articles