WebElement retrieved from frame "frameElement" does not equal WebElement ID of element located from parent frame
HI ,
for the mentioned issue 4305, unable to get the attributes of the current frame in which driver is switched.
For ex: switch to Frame with ID : frameID. Now un able to retrieve attributes of the frame for which driver was switched. Earlier some resolution is given in the Issue 4305 but it is not working. It is giving stale element exception even keeping static delay.
please provide a reproducible test case. Also this seems more like something to work out with fellow users on the users list: https://groups.google.com/forum/#!forum/selenium-users or on IRC first.
closing this for now until a reproducible test case is provided.
Hi Lukeis, Thank you very much for the reply.
Please find the reproducible Test case:
-
In our application after clicking on button, enables a Frame with a unique ID property. This ID is unique only after Frame was brought up into DOM. There is no static ID for this Frame until it was enabled in to Application. Once Frame was enabled this ID will be unique until browser session lasts.
-
Select a Frame with ID : "tab_Pane_View3" by using driver.switchTo.frame("tab_Pane_View3") API from TargetLocator interface.
-
Now try to get the self properties of the frame ( "tab_Pane_View3" ) after switch action performed.
Use case is : Just like Window handles , we need to store handles of Frames too. If it is not provided, at least if we provided API like getting any unique property of the frame element after switching to frame and toggle between the frames in more easy manner.
This is required because if we have multiple frames and if our test demands to shift between frames , before switching frames we can store some unique property of the frame and then toggle between other frames and come back to original frame again with out any calculations by unique attributes. which were store before switching
in the selenium-users group they I posted query and they provided below solution : but it is not working.
WebElement frameEl = driver.findElement(By.tagName("iframe")); driver.switchTo().frame(frameEl); // This will fail if frames are on different domains! WebElement el = (WebElement) ((JavascriptExecutor) driver).executeScript( "return window.frameElement"); assert frameEl.equals(el)
It appears that the WebElement returned from the javascript executor when returning frameElement are registered with different element id's (I'm not sure if we need to fix something here or not).
Here's an example showing how you can make it work:
WebDriver driver = new FirefoxDriver();
try {
driver.get("https://login.salesforce.com");
WebElement frameEl = driver.findElement(By.tagName("iframe"));
driver.switchTo().frame(frameEl);
// This will fail if frames are on different domains!
WebElement el = (WebElement) ((JavascriptExecutor) driver).executeScript(
"return window.frameElement");
// this frame is 'cross domain' and thus returns null
assert el == null;
// but the frame contains *another* iframe
// one used for tracking and is just 'about:blank', so cross domain does not apply
frameEl = driver.findElement(By.tagName("iframe"));
driver.switchTo().frame(frameEl);
el = (WebElement) ((JavascriptExecutor) driver).executeScript("return window.frameElement");
// need to switch to the parent frame to be able to compare the elements, since frameEl belongs to that context
driver.switchTo().parentFrame();
assert (Boolean)((JavascriptExecutor) driver).executeScript("return arguments[0] == arguments[1]", el, frameEl);
} finally {
driver.quit();
}
HI Lukies ,
Please find that the moment i used in my code with the below mentioned Java script after switching to frame. It is throwing below exception. There is no DOM refrersh, no reference went to stale, there is no page refresh. Application is idle. I even kept thread,sleep for 3 minutes, but still it gave me like stale exception. Below is my code.
driver.switchTo().frame("myFrame"); Thread.sleep(180000); WebElement el = (WebElement) ((JavascriptExecutor) driver).executeScript( "return window.frameElement");
org.openqa.selenium.StaleElementReferenceException: Element belongs to a different frame than the current one - switch to its containing frame to use it Command duration or timeout: 25.04 seconds For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:30' System info: host: 'MAVULA-LAP', ip: '10.176.181.61', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_55' Session ID: 589b4e07-fd80-4006-877d-c353ff651eac Driver info: org.openqa.selenium.firefox.FirefoxDriver Capabilities [{platform=XP, databaseEnabled=true, cssSelectorsEnabled=true, javascriptEnabled=true, acceptSslCerts=true, handlesAlerts=true, browserName=firefox, webStorageEnabled=true, nativeEvents=false, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=31.7.0}] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599) at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:268) at org.openqa.selenium.remote.RemoteWebElement.getAttribute(RemoteWebElement.java:123)
@malligr8 That is working as intended
Hi Lukies but i am unable to get properties of the frame which i switched. Anything i am missing after switching frame. Please help me in resolving this .
closing as won't fix.. an edge case that there are workarounds for