Ruby 1.9 · selenium · selenium-webdriver · Selenium-webdriver

To access the elements within IFrame using Selenium WebDriver (Ruby)

Situation :

User want to click the field which is placed within 2 IFrames using selenium webdriver.

Field — Friendship

Source code for “Friendship” — <nobr>Friendship</nobr>

Frame ID’s –” nav”  and “JobplaceFrame”

Code:

require ‘rubygems’

require ‘selenium-webdriver’

$browser = Selenium::WebDriver.for :ie

$browser.get "http://URL.com”

current_title=$browser.title
if current_title == “TITLE OF THE WEBPAGE”
puts “step 1 passed”
else
puts “step1 failed”
exit
end

$browser.switch_to.frame(‘nav’) #parent Frame
$browser.switch_to.frame(“JobplaceFrame”) #Child frame

options=$browser.find_elements(:tag_name=>”nobr”)

options.each do |nobr_field|
if nobr_field.text == 'Friendship'
nobr_field.click
break
end
end

selenium · selenium ide · selenium-webdriver · Selenium-webdriver

Selenium IDE to Selenium WebDriver Ruby code conversion

1. Install Latest Mozilla Firefox browser (Now 6.0.x)

2. Install Latest Selenium IDE(Now 1.2.0) from http://seleniumhq.org/download/

3. Restart Fire fox — Open Selenium IDE  (Tools –> Selenium IDE)

4. Options — Click Options

5. Change the settings like below



6. Record few actions in IDE and save the recorded script.

7.  Refer Screenshot to convert it into Selenium WebDriver ruby code.