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 it. Also, i had trouble getting the old selenium to work with ruby 1.9.1 in windows so I thought i'd look for an alternative.
So far i've done this with my script:
require "selenium-webdriver"
driver = Selenium::WebDriver.for :firefox
driver.get "https://example.com"
element = driver.find_element(:name, 'username')
element.send_keys "mwolfe"
element = driver.find_element(:name, 'password')
element.send_keys "mypass"
driver.find_element(:id, "sign-in-button").click
driver.find_element(:id,"menu-link-my_profile_professional_info").click
driver.find_element(:id,"add_education_btn").click
country_select = driver.find_element(:name, "address_country")
So basically I'm logging into my site and trying to add an education entry to my user profile.. I have a reference to a select box with options (in the country_select variable) and now i want to select an option with a given value.. I don't see how to do this in the new client.. The only thing I can think of doing is looping through all the options until I find the one I want, and then call execute_script:
http://selenium.googlecode.com/svn/trunk/docs/api/rb/Selenium/WebDriver/Driver.html#execute_script-class_method
method to set the selectedIndex.
Is there any other way to do this?
In the java api for selenium 2.0/webdriver here: http://seleniumhq.org/docs/09_webdriver.html
there is an example of doing this
Select select = new Select(driver.findElement(By.xpath("//select")));
select.deselectAll();
select.selectByVisibleText("Edam");
It doesn't appear that the ruby version has this feature though unless I'm missing something.
Any help would be appreciated.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…