How can I select an option from a dropdown using Ruby Selenium Webdriver?

0 votes
How can I select an option from a dropdown using Ruby Selenium Webdriver?
Aug 26, 2019 in Selenium by Swasti
897 views

1 answer to this question.

0 votes

Hey Swasti, you can try following lines of code to perform selection of an option from a dropdown:

driver = Selenium::WebDriver.for :firefox
driver.navigate.to "http://facebook.com"

options = select_list.find_elements(:tag_name => "option")
options.each do |opt|
  if opt.text == "March"
    opt.click
    break
  end
end
answered Aug 26, 2019 by Anvi
• 14,090 points
This works fine.
drop = driver.find_element(:id, "month")
choose = Selenium::WebDriver::Support::Select.new(drop)
choose.select_by(:text, "Feb")

Hi @Pranish Katwal, thank you for your contribution to the Edureka Community.

Register/Sign up on the community to gain points for further contributions. You may ask questions, answer, upvote, and downvote an answer. Each of these would fetch you points and you could be among the top contributors and win exciting merchandise from Edureka.

Cheers!

Related Questions In Selenium

0 votes
1 answer

How can I select date from a datepicker div using Selenium Webdriver?

Hey Jeevika, you can use following automation ...READ MORE

answered Jul 15, 2019 in Selenium by Abha
• 27,930 points
7,097 views
0 votes
1 answer

Can I select multiple options from a dropdown using Python Selenium webdriver?

Hi Dhwani, you can use following code ...READ MORE

answered Jul 30, 2019 in Selenium by Abha
• 27,930 points
1,386 views
0 votes
1 answer

Select an item from a dropdown list using Selenium WebDriver

Use this then it will work - new ...READ MORE

answered Apr 9, 2018 in Selenium by Vardy
• 2,360 points
4,686 views
0 votes
1 answer

How can I locate web elements from a web page using Selenium Webdriver?

Hey @Dushyant, Locating elements in WebDriver is ...READ MORE

answered May 28, 2019 in Selenium by Shreya
871 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,510 points
3,465 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31 in Selenium by Sri
• 2,970 points
4,481 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,890 points
2,560 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 2 in Selenium by Sri
• 2,970 points
2,792 views
0 votes
1 answer
0 votes
1 answer