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

前端 未结 10 1337
难免孤独
难免孤独 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 01:14

    pnewhook got it but I'd like to post the ruby version here so everyone can see it:

    require "selenium-webdriver"
    driver = Selenium::WebDriver.for :firefox
    driver.manage.timeouts.implicit_wait = 10
    driver.get "https://example.com"  
    country_select = driver.find_element(:id=> "address_country")
    options = country_select.find_elements(:tag_name=>"option")
    options.each do |el|
        if (el.attributes("value") == "USA") 
            el.click()
            break
        end
    end
    

提交回复
热议问题