Window disappears and can not be detected by Selenium.

124 views
Skip to first unread message

Eugene Shragovich

unread,
Jan 28, 2015, 12:51:59 AM1/28/15
to seleniu...@googlegroups.com
Hi,

I am running IE 8 and Selenium 2.42.1

Please consider the below scenario:
1. Click on a link on page -> New IE window opens
2. Create a list of current window handles
3. Try to switch to each one of the handles

Problem: The frame does not exists anymore.

So what I wanted to check first is what happens in the time between when the second window appears for the first time and when I actually try to switch to it. For that I created a simple loop that samples all available window handles every 0.01 sec:

for i in range(30):
     print "All sessions:"
     for handle in self.driver.window_handles:
          print handle
  print self.driver.title
  print "========"
time.sleep(0.01)

What I get is the following result:

All sessions:
ad5328c1-28a8-4990-a83e-4cf22e7444d6
394a069b-1f57-4e93-9465-da4ef3f72f7b
========
All sessions:
ad5328c1-28a8-4990-a83e-4cf22e7444d6
========
All sessions:
ad5328c1-28a8-4990-a83e-4cf22e7444d6
========
All sessions:
ad5328c1-28a8-4990-a83e-4cf22e7444d6
. . .

So initially, there are 2 handles/windows appear but you can see that after the first (sometimes it is second or third) sample the second, one of the handles disappear and only one is left.
What's even more interesting, is that when I check the driver title, it shows me the name of the first window but when I interact with the driver, I see that it is actually focused on the newly created window.

This all is super confusing and I hope that I my explanation makes sense. If it does not, please let me know and I will elaborate.

Will be great to hear some ideas as to why such behavior could occur? To me it looks like a bug.

Thanks!

Selenium Framework

unread,
Jan 28, 2015, 5:28:32 PM1/28/15
to seleniu...@googlegroups.com
So I tried your scenario with Ruby implementation of Selenium webdriver (using watir, which is a wrapper over selenium webdriver) - Used IE8 and 2.44.0 -- Seems like there is consistent behavior , maybe it is 2.42.1 version that is problematic

Ruby Code (#test.rb)
================
require 'watir-webdriver'
browser = Watir::Browser.new :ie
browser.goto "http://seleniumframework.com/Practiceform/"
browser.button(id: "button1").click
for i in 1..10
puts "All window handles"
for handle in browser.windows
puts handle
puts handle.title
puts "==========="
end
sleep 0.01
end
browser.quit

Java Code (Paste the code in SimpleTest.java)
package stepDefinitions;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class SimpleTest {
public static void main(String args[]) throws InterruptedException {
WebDriver driver = new InternetExplorerDriver();
driver.get("http://seleniumframework.com/Practiceform/");
driver.findElement(By.id("button1")).click();
for(int i=0;i<30;i++) {
System.out.println("All sessions");
for(String handle:driver.getWindowHandles())
{
System.out.println(handle);
System.out.println("Current handle-"+driver.getWindowHandle());
System.out.println("=========");
}
Thread.sleep(10);
}
driver.quit();
}
}


OBSERVATIONS

In both the cases, I did not notice any confusing behavior as you mentioned (The output files are attached)

1) In Ruby code , the focus was always on parent window handle
2) In Java code , the focus was always on parent window handle


Cheers,
www.seleniumframework.com
JavaCode_output.txt
RubyCode_output.txt
Reply all
Reply to author
Forward
0 new messages