Answer a question

I've done a search and most of the related google results have returned just in general selecting an element from a dropdown. However the ID's in this case for the elements in the dropdown are dynamically generated unfortunately.

This is for a base test case, so I basically just need to select for example the first one. The text is also the same for the elements in the dropdown (not sure if that helps).

Is there such an example of this?

Im using cucumber with caybara(using selenium driver) integration

Answers

You can find the first option element and then use the select_option method to select it.

For example, if the select list has an id "select_id", you can do:

first('#select_id option').select_option

As @TomWalpole mentions, this will not wait for the element to appear. It would be safer to do one of the following:

first('#select_id option', minimum: 1).select_option

or

find('#select_id option:first-of-type').select_option
Logo

Python社区为您提供最前沿的新闻资讯和知识内容

更多推荐