How do I set an option as selected using Selenium WebDriver (selenium 2.0) client in ruby

前端 未结 10 1348
难免孤独
难免孤独 2020-12-14 00:46

I am trying to get familiar with the new ruby selenium-webdriver as it appears more intuitive mostly than the previous version of selenium and the ruby driver that went with

10条回答
  •  执念已碎
    2020-12-14 00:56

    require "selenium-webdriver"
    webdriver = Selenium::WebDriver.for :firefox
    
    driver.navigate.to url
    
    dropdown = webdriver.find_element(:id,dropdownid)
    return nil if dropdown.nil?
    selected = dropdown.find_elements(:tag_name,"option").detect { |option| option.attribute('text').eql? value}
     if selected.nil? then
      puts "Can't find value in dropdown list"
     else
      selected.click
     end
    

    In my case this is only one working sample.

提交回复
热议问题