Re: switchTo().defaultContent() does not work if frame is closed

3,950 views
Skip to first unread message

Phil

unread,
Oct 30, 2012, 8:37:23 AM10/30/12
to webd...@googlegroups.com
I'm having a similar issue where I can access the iframe and click it's contents no problem but because it closed itself before I get a chance to call switchTo().
defaultContent() I cannot access the same frame again.  Any help would be greatly appreciated.

Phil

Santosh Hulisandra Srikanta

unread,
Oct 30, 2012, 11:36:22 AM10/30/12
to webd...@googlegroups.com
instead of using driver.switchTo().defaultContent() use   driver.switchTo().window("window name") i have the same scenario and   driver.switchTo().window() works for me.

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To view this discussion on the web visit https://groups.google.com/d/msg/webdriver/-/8vXD6utmyaIJ.

To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.



--

/Santosh

darrell

unread,
Oct 30, 2012, 10:02:55 PM10/30/12
to webd...@googlegroups.com
This is an odd one. I worked for someone who abused iframes and popup windows. I definitely had a point where I would click something in the default iframe which would pop open a window. I'd then select something from the popup and it would close the popup. I then switched to defaultContent().

I was using an older version of Selenium. It was this year however. Selenium 2.18.0 or something. So it is possible this stopped working at some point but I'm doubtful.

The other possibility is you are doing something else which 'works' but causes Selenium to fail further down the scenario. I would try to reduce the problem to the minimum lines of code. For example, one application would require:

  1. Login
  2. Find and click element
  3. Find the popup and switch to it
  4. Select a value from the popup
  5. Switch to defaultContent()
  6. Assert
Most often the act of reducing the problem to a snippet I could post here (or file with a defect report if it was an application defect) I would learn some new things and figure out the real problem myself.

Darrell


On Monday, 29 October 2012 07:52:26 UTC-7, Rino van Dam wrote:
I have a page where a popup is created through iFrames.

- I use switchTo().frame("LookupWindow") to switch to the popup.
- I then successfully enter some text and look up a value
- Once the value is found, I click on on it (still on the popup)
- The popup now closes (because I clicked on the value in the popup)

This all works fine.

I then execute switchTo().defaultContent()

This is where webdriver hangs and never returns.  No error message, nothing.

Ideas?  Workarounds?

Thanks.

Alexei Barantsev

unread,
Oct 31, 2012, 3:17:42 AM10/31/12
to webd...@googlegroups.com
Hi, all,

On the one side, there is a test FrameSwitchingTest.testShouldBeAbleToCarryOnWorkingIfTheFrameIsDeletedFromUnderUs [1] in out test suite that passes in most browsers (except for andriod and opera) [2].

On the other side, there is an issue #2703 [3] that contains a reproduction scenario, and I've cheched it still fails in Chrome:

<code>
import org.openqa.selenium.*
import org.openqa.selenium.firefox.*
import org.openqa.selenium.chrome.*

driver = new ChromeDriver()


tinymcesmileyPopupPluginLink = driver.findElement(By.cssSelector(".mceIcon.mce_emotions"));
tinymcesmileyPopupPluginLink.click()
        
//switch to iframe popup
tinymcePopupFrame = driver.findElement(By.cssSelector("iframe[id^=\"mce\"]"))
driver.switchTo().frame(tinymcePopupFrame)

tinymcesmileyCoolIcon = driver.findElement(By.cssSelector("a>img[src='img/smiley-cool.gif']"))
tinymcesmileyCoolIcon.click()

//Chrome does a click but click does not RETURN.
driver.switchTo().defaultContent()
</code>

Сonclusion 1: there is a bug in the chromedriver, but it is not general, it appears in some edge cases.

Conclusion 2: chromedriver releases are rare and small issues can stay not fixed for long => you'd better look for a workaround.

Regards,
-- 
Alexei Barantsev
Software-Testing.Ru
Selenium2.Ru

Rino van Dam

unread,
Oct 31, 2012, 8:48:21 AM10/31/12
to webd...@googlegroups.com
Darrel, Alexei and others:  thank you for your replies.

First, I need to adjust my problem description.  Since I wrote the first post, I have realized that webdriver actually hangs immediately after executing the code that closes the popup.  It never gets to the line that switches back to the default content.  So:

- I use switchTo().frame("LookupWindow") to switch to the popup.
- I then successfully enter some text and look up a value
- Once the value is found, I click on on it (still on the popup)
- The popup now closes (because I clicked on the value in the popup)

This all works fine, but webdriver now hangs. It never gets to execute switchTo().defaultContent()

Also: this is on Firefox 15.0.1, Selenium (java) 2.25.

I have successfully used similar code (switchTo()... etc) in the past, but there the popup didn't close itself.  I am going to try and convince my employer to put a sample of this code up on a public page somewhere. 

darrell

unread,
Nov 1, 2012, 10:42:36 AM11/1/12
to webd...@googlegroups.com
It sounds like the problem is whatever happens when you click the element which closes the popup window. I'm guessing clicking the element transfers the value on the popup back to default content. If could be the way the developer is saving and transferring the information from the popup back to the default content is the problem.

If it is a timing issue, you could try putting in some Thread.sleep(5000) in various places. If this solves the problem you know it is a timing issue. You'll have to remove the various sleep statements until you figure out which one solved the problem. Once you know where you need to wait, change the sleep statement to wait for the appropriate event.

If it is something which the developer is doing which is illegal but works for humans, see if you can figure that out (use tools to examine the page for compliance, e.g. Tidy to examine HTML). Maybe doing the right thing will help WebDriver to work.

Could be you found an edge case where WebDriver fails. You'll have to find a workaround which will continue to work even if they fix the defect.

Finally, you could be dealing with more than one issue and might be looking for multiple solutions (lot harder to deal with).

Darrell

Phil

unread,
Nov 1, 2012, 11:08:38 AM11/1/12
to webdriver
My problem was fixed by upgrading to Firefox 14, previously used 13.
Thanks all

Rino van Dam

unread,
Nov 2, 2012, 9:38:42 AM11/2/12
to webd...@googlegroups.com
Have a demo site up where problem may be recreated.  Updated issue 2703 on code.google.com with the necessary info.
Reply all
Reply to author
Forward
0 new messages