0

I am using selenium to perform screen scraping on some application(url).I am using IE/Firefox driver.Can we open the browser which selenium opens in an iframe instead of opening it in a new window.To be more precise driver.get should open the url in an iframe and not a window.

Akhilesh Mohare
  • 45
  • 2
  • 13

1 Answers1

1

No. You can't open a browser inside an IFRAME. The contents of an IFRAME are always displayed by the same browser that displays the IFRAMEing page.

How to work around this strongly depends on what you are trying to accomplish and on whether you are using Selenium 1 (a browser plugin that rewrites pages by injecting JavaScript into them) or Selenium 2 (which uses WebDriver to communicate with browsers). But I'm pretty sure you'd need to rewrite some of the Selenium software.

reinierpost
  • 8,425
  • 1
  • 38
  • 70
  • Using Selenium 2 webdriver,I suppose its practically impossible to do it using selenium.Any other scraper which can get me a existing broswer session handler? – Akhilesh Mohare Aug 22 '14 at 11:24
  • What are you trying to accomplish? – reinierpost Aug 22 '14 at 13:15
  • developing an interactive web scraper web application for automatic login,etc.Have a jsp page with 2 iframes.One will invoke the scraping code and whichever url needs to be scraped will be shown in Iframe(user will be able to see the steps) – Akhilesh Mohare Aug 25 '14 at 06:13
  • 1
    In that case I think you'll need to build a web application that provides this interface to the user and interacts with the target web application using Selenium. – reinierpost Aug 25 '14 at 08:38
  • driver.get() will always open a new broswer window because i dont seem to find any way to pull the scraping page into an Iframe.My WebApplication always will call driver.get(3rd party url). – Akhilesh Mohare Aug 25 '14 at 09:57
  • 1
    1) You can rewrite the page after issuing the get() to wrap it inside the IFRAME (and hope you can do that in such a way as not to break the actual web application), or 2) You can use two browsers, one controlled by your Selenium application and the other used by the user to view your web application, but that will break down when the website relies on complex interaction with a lot of JavaScript in the browser, as that JavaScript will need to run both in the user's browser and in the browser controlled by Selenium. – reinierpost Aug 26 '14 at 07:06
  • 2nd method can be done but want a single page to display everything and also everything will be on client side.So it wont be of any use.can you explain a little bit about the 1st step.I was not able to understand the rewriting. – Akhilesh Mohare Aug 26 '14 at 07:59
  • The Selenium API wasn't designed to allow a page to be modified, but it can execute arbitrary JavaScript code, which can; e.g. you could do something like [this](http://stackoverflow.com/questions/9567966/easiest-way-to-alter-page-content-dom-using-selenium). – reinierpost Aug 26 '14 at 12:29