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

55 comments:



  1. Thank you for taking the time to provide us with your valuable information.

    Installment loans in Mississippi
    Payday loans in Mississippi
    Title loans in Mississippi

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

    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. 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

  5. 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
  6. Hi,
    Thanks for sharing this. It is very useful and helpful information... keep sharing.

    thank you
    Selenium training in Hyderabad

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

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

    ReplyDelete
  9. 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
  10. Click Here Best RPA Online Training to go to RPA Online Training Institute Details .

    ReplyDelete

  11. 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
  12. It's interesting that many of the bloggers to helped clarify a few things for me as well as giving.Most of ideas can be nice content.The people to give them a good shake to get your point and across the command
    best rpa training in bangalore
    rpa training in pune | rpa course in bangalore
    RPA training in bangalore
    rpa training in chennai

    ReplyDelete
  13. This is an best post. It is Really very informative concept.I like it and help me to development very well.Thanks alot for this brief explanation and very nice information.Keyword

    ReplyDelete
  14. teknik jitu yang dapat diterapkan untuk mendapatkan hasil maksimal. Untuk itu ikuti sampai tuntas penjelasan yang akan diberikan berikut ini.
    asikqq
    dewaqq
    sumoqq
    interqq
    pionpoker
    bandar ceme terpercaya
    hobiqq
    paito warna terlengkap
    bocoran sgp

    ReplyDelete
  15. thank you so much for this nice information Article, Digital marketing is tha good skill in grouth tha career For website creation, promotion and development contact here. For your digital marketing needs just have a look at Click Perfect.best oracle training in bangalore

    ReplyDelete
  16. Lovely blog ..! I really enjoyed reading this article. Thank you for sharing such a wonderful post
    aws Training in Bangalore
    python Training in Bangalore
    hadoop Training in Bangalore
    angular js Training in Bangalore
    bigdata analytics Training in Bangalore.Oracle Applications Training in Bangalore

    ReplyDelete
  17. Really very happy to say, your post is very interesting to read. I never stop myself to say something about it. You’re doing a great job. Keep it up…

    Advance your career in Selenium by doing Selenium Course in Pune with 3RI Technologies.

    ReplyDelete
  18. Thanks for sharing the information...
    SEO Training in Bangalore | SEO Course Fees | Best SEO Classes - Join SEO Training in Bangalore at i Digital Academy and learn how to increase your website Traffic by
    Google Certified Trainers with 100% Placements and affordable course fees. Book a Free Demo!

    ReplyDelete
  19. MDSU BCOM 1st, 2nd & Final Year
    TimeTable 2020

    I like this topic.This site has lots of advantage.I found many interesting things from this site. It helps me in many ways.Thanks for posting this again.
    Rajasthan University BCOM 1st, 2nd & Final Year
    TimeTable 2020

    RDVV BCOM TimeTable 2020
    UOK BCOM 1st, 2nd & Final Year
    TimeTable 2020

    ReplyDelete
  20. Thanks for your marvelous posting! I really enjoyed reading it. you're a great author. I will be sure to bookmark your blog and will come back very soon..God bless uou HDPE Pipe Fittings

    ReplyDelete
  21. can you cut led lights and they still work, LED strip lights will carry on working after they've been cut as long as you cut along the designated lines. ... Cutting elsewhere on the LED strip will cause that circuit, and potentially the whole strip, to cease working.

    ReplyDelete
  22. LED Strips - Swimming Pools ... Swimming pool led strip lights is especially designed to be submersed in water. The strip and connectors are larger than normal strips.

    ReplyDelete
  23. See our picks for the best 5 Led Lights Behind Tv For Ambiances in US. Find the Top products of 2021 with our Buying Guides, based on hundreds of reviews!

    ReplyDelete
  24. First You got a great blog. I will be interested in more similar topics. I see you got really very useful topics, I will be always checking your blog thanks.

    BCom Time Table

    BCom 1st year time table

    BCom 2nd year time table

    BCom 3rd year time table

    ReplyDelete
  25. Wireless LED Lights are designed to increase safety, security and convenience anywhere around the home. Signature features include motion.

    ReplyDelete
  26. Fast-track your data analytic and machine learning course with guaranteed placement opportunities. Most extensive, industry-approved experiential learning program ideal for future Data Scientists.

    ReplyDelete
  27. Appreciated that you have wonderful content. Digiperform can help you better content for your business, You just need to get enrolled in one of our courses. Digiperform offers the best digital marketing course in Lucknow as well as all over the globe.
    Join Digital Marketing Institute in Lucknow

    ReplyDelete
  28. I thoroughly enjoyed reading your article on selecting dropdowns in Ruby Selenium. Your clear explanations and step-by-step guide make it an invaluable resource for anyone working with Selenium in a Ruby environment. The detailed code snippets and explanations have greatly enhanced my understanding of handling dropdowns effectively.

    On a related note, I would like to share my positive experience with Imarticus Learning's Data Science Course. The course not only provides comprehensive coverage of data science concepts but also offers hands-on experience with tools like Python, R, and SQL. The practical projects and industry-relevant curriculum have significantly boosted my skills and confidence in the field. The expert faculty and supportive learning environment at Imarticus Learning have made my data science journey enjoyable and rewarding. I highly recommend it to anyone looking to embark on a successful career in data science.

    ReplyDelete
  29. I thoroughly enjoyed reading your article on selecting dropdowns in Ruby Selenium. Your clear and concise explanations make it easy for both beginners and experienced developers to understand and implement the concepts. The step-by-step approach and code snippets provided are extremely helpful.

    In addition to your insightful content, I would like to share my positive experience with Imarticus Learning's Data Science Course. Their comprehensive curriculum, hands-on projects, and expert instructors create a dynamic learning environment. The course not only covers essential data science concepts but also emphasizes practical application, ensuring students are well-prepared for real-world challenges. Imarticus Learning's commitment to quality education and industry relevance sets it apart, making it an excellent choice for anyone looking to embark on a rewarding journey in the field of data science. I highly recommend checking out their program for those seeking a robust and career-focused learning experience.

    ReplyDelete
  30. For the best digital marketing courses in Patna
    , look for programs that provide comprehensive coverage of key digital marketing domains including SEO, SEM, social media marketing, content marketing, and email marketing. Designed for both beginners and experienced professionals, these courses offer a blend of theoretical knowledge and practical application through hands-on projects, live campaigns, and industry case studies. Additionally, many of these programs offer robust placement support, helping graduates secure positions in leading companies and kickstart their digital marketing careers.

    ReplyDelete
  31. Great article! The step-by-step guide on selecting dropdowns in Ruby Selenium is very helpful for beginners and experts alike. For anyone interested in expanding their skill set further, especially in the realm of digital marketing, I highly recommend checking out this Advanced digital marketing course in delhi . It's a fantastic way to boost your knowledge and practical skills in a rapidly growing field. Thanks for the valuable insights!

    ReplyDelete
  32. Enroll Best Seo Courses In Delhi and gain expertise in all aspects of SEO. This course covers everything from keyword research, on-page SEO, technical SEO, and content optimization to advanced link-building strategies and local SEO tactics. You’ll learn how to analyze websites, perform SEO audits, and implement changes that lead to measurable results.

    ReplyDelete