-1

I have installed watir-webdriver in my rails application, I want to show the preview of the site instantly, I want to show watir click events on the same page not in new window/tab, here I want to show the live preview inside iframe on the index page, I tried following:

app/models/preview.rb

def self.live_preview
    browser = Watir::Browser.new :firefox, profile: 'MR'
    browser.goto "http://example.com"
    browser.text_field(id: 'email').set('test@gmail.com')
    browser.text_field(id: 'password').set('password')
    browser.button(name: 'commit').click
    browser.button(name: 'learn_more').click
  end

app/views/watir.rb

<%= Preview.live_preview %>

app/views/index.html.erb

<iframe id="preview" src="/watir"></iframe>

When the index page gets loaded it opens the new tab then all the events are executed but I want with in the same page

I want similar to watir-classic mentioned here to run in firefox on ubuntu

Community
  • 1
  • 1
M.R
  • 610
  • 2
  • 10
  • 34
  • can you do what you want manually, by taking the browser to a given page and clicking on things etc? if not, you won't be able to do it with Watir. If the code on the page opens a new tab when used manually, it will do that when driven by watir, or any other browser driver that sits on top of webdriver.. because the purpose of these tools is to interact with the browser as a user would. If you could not do something manually, then it is doubtful you would be able to do it via watir-webdriver as we cannot just magically make a browser do something it would not normally do. – Chuck van der Linden Apr 24 '15 at 20:16
  • @ChuckvanderLinden Yes, I can do it manually it's just some click events inside an iframe and I want to attach existing browser window not with new window in firefox – M.R Apr 25 '15 at 04:18

1 Answers1

0

Yes By following way you can click link in iframe

require 'watir-webdriver'
b = Watir::Browser.new
b.goto "index_page"    
b.frame(:id => 'top_right').link(:index => 0).click
Rajarshi Das
  • 11,778
  • 6
  • 46
  • 74
  • iFrame is already present in the index page I want to render watir events inside 'preview' iFrame, b.goto will redirect to new tab, I don't to want new window/tab – M.R Apr 23 '15 at 10:37
  • first you have to go the index page where is the iframe has then you can detect the iframe by `b.frame(:id => 'top_right')` then you can click any link on it by `.link(:index => 0).click` index should be proper – Rajarshi Das Apr 23 '15 at 10:40
  • I have index page that contains preview iFrame, I want to execute watir-webdriver events inside preview iFrame – M.R Apr 23 '15 at 10:42
  • I need similar to watir-classic for ubuntu + firefox – M.R Apr 23 '15 at 12:24