How to select an item from the drop-down list using the Prism site?

I have the following elements defined on the SitePrism page:

element :type, "select[id='type']" elements :type_options, "select[id='type'] option" 

And in my definitions of cucumber, I have the following code to select an item from a selection window based on the value of the elements:

 @app.new.type_options.each {|name| name.click if name.text.upcase == value.upcase} 

I don't really like this implementation, but it works fine when starting Capybara in chrome, but it doesn't work when I run it headless, so I think there should be an alternative / better way to select dropdown items.

Ideally, I would like to do something like @app.new_r.r_type.select 'value' , but I cannot figure out how to do this in SitePrism.

So my first question is: can someone recommend an elegant way to select an item from the drop-down list based on the value from SitePrism?

And my second question: any idea why the code above does not work when working without heads?

+4
source share
1 answer

I had a similar problem, and I could not get her to choose the right option. I came across this question and it made me realize that the problem is that you have to send the text, not the value, to select ().

For example, if I have HTML, for example

 <select id="things"> <option value="thing1">The First Thing</option> <option value="thing2">The Second Thing</option> <option value="thing3">The Third Thing</option> </select> 

And in my SitePrism :: Page class, I have:

 element :things, "select[id='things']" 

I thought I needed to do:

 @my_page.things.select("thing1") 

This does not work. Instead, you need to do:

 @my_page.things.select("The First Thing") 

I know this is a little different than what you are trying to select based on the value you get from SitePrism as originally set. But I thought that this difference about what to pass to select () might help someone.

+10
source

Source: https://habr.com/ru/post/1484214/


All Articles