Search Here!

Saturday, February 16, 2013

Refresh Iframe Using WebDriver

Webdriver has a method to refresh current page void refresh() but if page contains multiple IFrame's and we need to refresh IFrame only not whole page then use the under given method to refresh the IFrame through Java Script Executor-

/// Refresh the current selected iframe.
/// This is name of the Iframe.
/// Executes JavaScript in the context of the currently  selected frame or  window.
/// The script fragment provided will be executed as the body of an anonymous function.

/// Indicates that a driver can execute JavaScript, providing
/// access to the mechanism to do so.

protected void RefreshIFrameByJavaScriptExecutor(string iFrameName)
          ((IJavaScriptExecutor)WebDriver).ExecuteScript(string.Format("document.getElementById('{0}').src = " + "document.getElementById('{0}').src", iFrameName));

No comments:

Post a Comment