As a QA one of the most common action on web might be to select values from dropdown but sometimes you have huge lists and all does the same thing in the end so you might want to select random value from dropdown without bothering too much about values is gonna be. I will try to cover this topic in a project that is using Ruby Capybara api but you can adapt it to any other framework/languages.
Imagine a simple scenario , you want to find out whats the estimate for your house that you live in London:
Given Im on Zoopla home values page When I click on button "Get a Zoopla estimate" And I type a post code "NW3 5DR" When I click on button Locate address And I choose an address ... ... ......
So on the 5th step you might have a bunch of 50 addresses , choosing any of them will take us to the same page for a property ID, so we don’t really need to hardcode the address we can randomise it. Some people might criticise me but excuse me I’m a practical guy.
Solution for select random value from dropdown
Simple as that , we get all the options , in my case I get read of the option with text “My address is not listed” and I get read of the first option named “Select” , also if there are just 2 options , first will be “Select” and second will be the actual address we select the address.
This article is just the beginning of the a big selenium Tips suite that will be posted on testing repository. Meanwhile you can check How to getText from the disabled input field in selenium webdriver.
Happy testing guys!