Saturday 17 November 2012

Working with frames/iframes in Selenium/WebDriver

Hey Guys,

It has been long time, anything posted in the blog from my side. Busy in trying a new tool WatiN. But this post is related to Selenium and WebDriver. How Selenium2 or Selenium -WebDriver handles frames/iframes. In a very simple word, Frames or IFrames can be treated as web page inside a web page. And no wonder, Selenium also treats them in same line. That means, you have to switch to a frame, to find elements present inside that frame. And you need to come out of the frame when you want to find elements outside of the frame.

1st thing to remember is frame/Iframes are nothing  but Web Elements in side a web page. So you can use findElement() method to find out the frame/Iframe. But there is another simple way, where you only provide the name of the frame and Selenium and Web Driver automatically switch the control to that frame.

Consider the below HTML portion, where two frames are present. To find out an element inside those frames, you need to switch the control to that frame.
######################################################
<frame name="Frame1" id="Frame1">
        -----------
        -----------
        -----------
 </frame>

 <frame name="Frame2" id="Fram2">
        ----------
        -----------
        -----------
  </frame>
######################################################


Lets find out frame1 using find element technique:
WebElement frame = driver.findElement(By.Name("Frame1"));
   or 
WebElement frame = driver.findElement(By.Id("Frame1"));

Now you can use frame object to switch the control.
driver.switchto.frame(frame);

In the method above, you need get the object web element and then use it in switchto method.

But you can directly call the switchto  method on frame name like:
driver.switchto.frame("Frame1");

You can also switch to frame by using index of the frame.
In the above example, to switch to "Frame1" using index, the code will be like :
driver.switchto.frame(0);

And the last thing is once you switch to a frame, then you must go out of the frame to find elements outside of the frame boundry.
driver.switchto.defaultcontent();

Please feel free to leave a comment about this post. I would like to hear from you guys if you have any specific issue/doubts related to handling frames in selenium then I would try to clear.

Thanks!!

Saturday 3 November 2012

Selenium 2.26 Released!!!

Hey Guys,

Selenium 2.26 release, yet to hit SeleniumHQ but if you want to download then click on below link.
Selenium 2.26 download link.

Here is the Change Log :

v2.26.0
=======
WebDriver:
  * Updated OperaDriver to 0.15.
  * Added transparency support to the Color class.
  * Increased lock time a bit for the FirefoxDriver to make tests more 
    stable on Windows.
  * Added the enablePersistenHover capability to allow the user to specify
    whether to use the persistent hover thread in the IE driver. Defaults
 to true for IE.
  * Added support for native events for Firefox 15 and 16.
  * Removed deprecation from ChromeDriver constructors that take a Capabilities
    object. Also added a method to set experimental options in ChromeOptions
 which may be used to set options that aren't exposed through the ChromeOptions
    API.
  * Fixed SafariDriver to allow calling .quit() consecutively without error.
  * Modified FirefoxDriver to use atoms to switch between frames.
  * FIXED: 4535: Hover still does not work perfectly in IE.
  * FIXED: 4676: Unable to fire javascript events into SVG's. 
  * FIXED: 4320: Impossible to IE run tests in parallel via TestNG.
  * FIXED: 4309: 'Could not convert Native argument arg 0' error with Firefox.
  * FIXED: 4593: Alert.accept() Cancels the Resend Alert/Dialog Box.
  * FIXED: 4321: Upgrade HtmlUnitDriver to HtmlUnit 2.10.
  * FIXED: 4639: Webdriver 2.25 fails to quit on Windows.
  * FIXED: 3774: New SafariDriver sessions do not come with a clean profile.
  * FIXED: 4375: Executing javascript hangs Firefox.
  * FIXED: 4203: Java SafariDriver has limited websocket frame size.
  * FIXED: 4165: WebDriver fails on a machine with no IP address.
  * FIXED: 3969: SafariDriver should auto-dismiss alerts.

WebDriverJS:
  * FIXED: 4648: findElement errros not helpful.
  * FIXED: 4687: webserverjs cannot find module in node.js.
  * FIXED: 4649: Wrong Content-Length calculation in webdriverjs.
  * FIXED: 4425: Webdriver.js regression: webdriver.By.* selectors defect when
    using Node.js.

Grid:
  * FIXED: 4433: NPE at grid launch if invalid servlet class name is specified.
  * FIXED: 4526: elenium node stop responding when there are 2 or more tests
    waiting for a specific node.
  * FIXED: 2549: "-role hub" doesn't allow Firefox to starts.

Thanks!!

Related Posts

Related Posts...