Monday, 10 April 2017

Select dropdown in Ruby | Selenium


Note| 
 
Text in Blue [#PYTHON], Red [#RUBY], and Orange [#JAVA] can be edited or mentioned important for the entire blog. All the posts are practically done by me.


Select dropdown


Add below snippet in the step definition file,

When(/^I select using "([^"]*)" with data "([^"]*)" from "([^"]*)" on the xyz page$/) do |event, value, dropdown|
  yourpage_data = PageName.new(@driver)
  case event
    when "position"
      yourpage_data.select_by_position(value, dropdown)
    when "value"
      yourpage_data.select_by_value(value, dropdown)
    else
      raise ArgumentError, "can't find the event #{event}"
  end
end

Select by position

Make sure you create cucumber steps before step definitions; say,

And I select using "position" with data "1" from "your_locator" on the xyz page


Add the following snippets inside the page file,

your_locator_dropdown = @driver.find_element(:css => "your_css_locator")
your_locator = @driver.find_elements(:css => "your_css_locator")

def select_by_position(value, dropdown)
  __send__("#{dropdown}_dropdown").click
  __send__("#{dropdown}").each_with_index do |elem, index|
    if index == value
      elem.click
      break
    end
  end
end



Select by value

Make sure you create cucumber steps before step definitions; say,

And I select using "value" with data "demo_value" from "your_locator" on the xyz page


Add the following snippets inside the page file,

your_locator_dropdown = @driver.find_element(:css => "your_css_locator")
your_locator = @driver.find_elements(:css => "your_css_locator")

def select_by_value(value, dropdown)
  __send__("#{dropdown}_dropdown").click
  __send__("#{dropdown}").each do |elem|
    if elem.attribute("value").to_s == value.to_s
      elem.click
      break
    end
  end
end


Select by last value

Make sure you create cucumber steps before step definitions; say,

And I select using "last_value" with data "" from "your_locator" on the xyz page


Add the following snippets inside the page file,

your_locator_dropdown = @driver.find_element(:css => "your_css_locator")
your_locator = @driver.find_elements(:css => "your_css_locator")

def select_by_last_value(dropdown)
  __send__("#{dropdown}_dropdown").click
  (__send__("#{dropdown}").last).click
end


Select by text

Make sure you create cucumber steps before step definitions; say,

And I select using "text" with data "demo_text" from "your_locator" on the xyz page


Add the following snippets inside the page file,

your_locator_dropdown = @driver.find_element(:css => "your_css_locator")
your_locator = @driver.find_elements(:css => "your_css_locator")

def select_by_text(value, dropdown)
  __send__("#{dropdown}_dropdown").click
  __send__("#{dropdown}").each do |elem|
    if elem.text.to_s == value.to_s
      elem.click
      break
    else
      puts "#{elem.text} not matching #{value}"
    end
  end
end

40 comments:

  1. Very Useful information that i have found. don't stop sharing and Please keep updating us..... Thanks

    ReplyDelete
  2. Its fantatic explaintion lot of information gather it...nice article....
    seo company in Chennai

    ReplyDelete
  3. Nice tutorial iam reading your article really it is very helpful for providing a lot of information about Selenium …. Thank you Please keep share some more…………

    ReplyDelete
  4. you are posting a good information for people and keep maintain and give more update too.
    seo services india

    ReplyDelete
  5. Excellent blog, just found your tutorials searching and studying a little about selenium webdriver, appium and cucumber. I've installed for android and worked well, but i'm having trouble in how to install and configure this environment for iOS. Do you have any tutorial for iOS? best from Brazil

    ReplyDelete


  6. Its a wonderful post and very helpful, thanks for all this information. You are including better information regarding this topic in an effective way.Thank you so much

    Personal Installment Loans
    Title Car loan
    Cash Advance Loan

    ReplyDelete

  7. This information is impressive; I am inspired with your post writing style & how continuously you describe this topic.


    Pawn Shop

    Pawn Loans

    Pawn Shops

    Pawn Loan

    Pawn Shop near me

    ReplyDelete

  8. I have really enjoyed reading your blog posts. This information is impressive. I am inspired with your post.. I hope you post again soon.your post is very helpful for me. photos very nice.
    Java Training in Chennai

    ReplyDelete
  9. Hi,
    Thanks for sharing this. It is very useful and helpful information... keep sharing.

    thank you
    Selenium training in Hyderabad

    ReplyDelete
  10. It's A Really Great Post. Looking For Some More Stuff.
    SEO Training In BTM Layout

    ReplyDelete
  11. Best Digital Marketing company Anantapur

    helpful information, thanks for writing and share this information

    ReplyDelete
  12. At Coepd - (Center of Excellence for Professional Development) Manual & Selenium testing training program is designed to give participants the skills & knowledge to gain a competitive advantage in starting/enhancing a career in software testing. We provide the attendee's software testing service which is required to ensure that tested applications meet all application requirements. Participants receive up-to-date training in multiple areas in Software Testing and a thorough understanding of real-world projects. Our collaborative ecosystem comprising of Partnerships with Software Companies enables real time software test life cycle experience.

    http://www.coepd.com/TestingTraining.aspx

    ReplyDelete
  13. Its really an Excellent post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog. Thanks for sharing....

    Shriram Magizhchi
    Shriram Magizhchi Guduvancheri
    Shriram Magizhchi price
    Shriram Magizhchi Guduvancheri Chennai
    Shriram Magizhchi apartments
    Shriram Magizhchi flats
    Shriram Magizhchi review

    ReplyDelete
  14. Nice Sharing..! I have been following you for a couple of months now but this is my first time commenting on a blog post.

    selenium training in chennai

    ReplyDelete
  15. Robotic Process Automation (RPA) is one of the most exciting developments in Business Process Management (BPM) in recent history. Some industry experts believe it may be even more transformational than cloud computing transformational than cloud Automationminds team. (RPA)Automationminds lets you program in (RPA),
    Robotic Process Automation course

    ReplyDelete
  16. Very Great information.Thanks for sharing such a valuable information. Keep sharing like this.
    Best Selenium Training Institute In Hyderabad | Online Selenium Training

    ReplyDelete
  17. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.

    https://www.emexotechnologies.com/courses/software-testing-training/selenium-with-python-training/ Selenium with python Training in Electronic City

    ReplyDelete
  18. Awesome blog. It was very informative. I would like to appreciate you. Keep updated like this best sap simple finance online training institute in hyderabad

    ReplyDelete
  19. hi, nice information is given in this blog. Thanks for sharing this type of information, it is so useful for me. nice work keep it up. best sap simple finance online training institute in hyderabad

    ReplyDelete
  20. Click Here Best RPA Online Training to go to RPA Online Training Institute Details .

    ReplyDelete
  21. Nice post. By reading your blog, i get inspired and this provides some useful information. Thank you for posting this exclusive post for our vision.
    Selenium Training in Chennai | Selenium Training in Bangalore | Selenium Training in Pune | Selenium online Training

    ReplyDelete
  22. myTectra Placement Portal is a Web based portal brings Potentials Employers and myTectra Candidates on a common platform for placement assistance

    ReplyDelete
  23. As you have now understood the usage of ‘Record and Playback’ tool, the following are the different posts using which you can explore the functioning of ‘Selenium IDE’
    selenium Training in chennai

    ReplyDelete

  24. Those guidelines additionally worked to become a good way to recognize that other people online have the identical fervor like mine to grasp great deal more around this condition.

    python Training in Bangalore | python Training in Bangalore

    ReplyDelete