Interaction with elements - Selenium in ruby
In this section, let us see how we can automate buttons, drop downs, text boxes, links and much more. Entering data in Edit boxes – Below example will enter driver id in the text box with name – driverid
#find the element using name
element = driver.find_element(:name, 'driverid')
#enter data in the editbox - driverid
element.send_keys "79798982"
Selecting value from the combo boxes – Below code will select the value Brisbane from the drop down with id – region
option = Selenium::WebDriver::Support::Select.new(driver.find_element(:id,'region'))
option.select_by(:text, "Brisbane")
Clicking on links and buttons – Below code will click on link – Place order
element = driver.find_element(:link_text, 'Place order')
element.click
Reading element data
element = driver.find_element(:css, input[value="Australia"]')
puts "Element's class attribute is #{element.attribute('class')} "
#check if the checkbox is enabled. puts "Checkbox is enabled #{element.enabled?} "
#Check if the checkbox is selected
puts "Checkbox is selected #{element.selected?} "
#check if the checkbox is displayed.
puts "Checkbox is displayed #{element.displayed?} "
Web development and Automation testing
solutions delivered!!