WebDriver always opens an extra browser window

8,147 views
Skip to first unread message

Lindsay Wang

unread,
Feb 21, 2012, 11:35:00 PM2/21/12
to Selenium Users
Does anybody see this issue? It happens on IE9, not sure about other
browsers.
(WebDriver 2.16.0 Java)

Whenever I open an URL, say facbook.com, after a while (maybe 15
seconds), there is always a new browser window pops out,

with URL in address bar:
http://localhost:xxxxx/ (port number changes)

and content of webpage:
This is the initial start page for the WebDriver server.

The main browser window (facebook.com to some other URLs) works fine,
with or without closing the second window.

Thanks,
Lindsay

Jim Evans

unread,
Feb 22, 2012, 10:07:47 AM2/22/12
to Selenium Users
Hi, Lindsay. I'm a little confused about the sequence of events you're
talking about here. When your WebDriver code starts IE, you get the
(expected) initial page opened up. When and how are you attempting to
open the other URL? In your WebDriver code? When you create your
instance of InternetExplorerDriver, are you just using the default
constructor, or do you mess around with DesiredCapabilities?

--Jim

On Feb 21, 8:35 pm, Lindsay Wang <tasc...@gmail.com> wrote:
> Does anybody see this issue? It happens on IE9, not sure about other
> browsers.
> (WebDriver 2.16.0 Java)
>
> Whenever I open an URL, say facbook.com, after a while (maybe 15
> seconds), there is always a new browser window pops out,
>
> with URL in address bar:http://localhost:xxxxx/(port number changes)

Lindsay Wang

unread,
Feb 22, 2012, 7:09:50 PM2/22/12
to Selenium Users
WebDriver wd = new InternetExplorerDriver();

something else.....

public File saveScreenShot() {
  WebDriver augmentedDriver = new Augmenter().augment(this.wd);
        File f = null;
        if (augmentedDriver instanceof TakesScreenshot) {
            f = ((TakesScreenshot)
augmentedDriver).getScreenshotAs(OutputType.FILE);
        } else {
        return new File("could-not-take-screenshot");
}

it seems this method creates a new window, and then loses the
reference. augmentedDriver.quit() will only close the main window.

Lindsay




On Feb 22, 7:07 am, Jim Evans <james.h.evans...@gmail.com> wrote:
> Hi, Lindsay. I'm a little confused about the sequence of events you're
> talking about here. When your WebDriver code starts IE, you get the
> (expected) initial page opened up. When and how are you attempting to
> open the other URL? In your WebDriver code? When you create your
> instance of InternetExplorerDriver, are you just using the default
> constructor, or do you mess around with DesiredCapabilities?
>
> --Jim
>
> On Feb 21, 8:35 pm, Lindsay Wang <tasc...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Does anybody see this issue? It happens on IE9, not sure about other
> > browsers.
> > (WebDriver 2.16.0 Java)
>
> > Whenever I open an URL, say facbook.com, after a while (maybe 15
> > seconds), there is always a new browserwindowpops out,
>
> > with URL in address bar:http://localhost:xxxxx/(portnumber changes)
>
> > and content of webpage:
> > This is the initial start page for the WebDriver server.
>
> > The main browserwindow(facebook.com to some other URLs) works fine,

Mike Riley

unread,
Feb 23, 2012, 2:20:28 PM2/23/12
to Selenium Users
Lindsay,

I do this and it works fine for me since I implemented it. Currently
I am running on 2.14.0, but I have also tried 2.19.0 and I did not see
any such issue. I have posted my code before, but here it is again in
case it helps you. I am using TestNG, so this places the reference to
the image file in the log output, plus each filename is made unique so
I can have multiple screen shots per test suite:

/**
* This is used when trying to capture a screenshot at the time of
failure.
* This is based on a recommendation from the Selenium user group:
* <a href="http://groups.google.com/group/selenium-users/
browse_thread/thread/55066381d492c716#">
* Automatic Screenshot on error</a>
* @return WebDriver generated by Augmenter class.
* @see <a href="http://seleniumhq.org/docs/
04_webdriver_advanced.html#taking-a-screenshot">
* taking-a-screenshot</a>
*/
private WebDriver getScreenshot()
{
return new Augmenter().augment(driver);
} // getScreenshot

/**
* This method is simply used to output a blank line to both the
console and
* the reporter log. The funny thing about Reporter.log() is that
if you
* use the method that goes to both then it will not handle XHTML
tags and
* seems to just send them out as-is to the console. So instead
of doing
* two calls every time I need a blank line (one for console and
one for the
* log), I just wrote this method to do it.
*/
private void logBlankLine()
{
System.out.println(""); // Output a blank line on the console
Reporter.log("<br />"); // Output a blank line in the log
} // logBlankLine

/**
* This is used to log any exception that happens during a test.
It must be
* called from the test, but it will not flag the test as having
failed, as
* the exception might be what was expected. The stack trace,
exception
* message string, and explanation are all written to the console
as well as
* the Reporter log (which is part of the TestNG Results page).
In addition
* a screenshot is captured to a file and an img tag is written
out to the
* Reporter log so it is visible on the web page for Reporter
output and
* Results web pages. A blank line will be output both before and
after the
* exception info, to help it standout from other output.
* @param explanation This should be some string that explains
what was
* going on when the exception occurred. Something that will make
sense to
* the person reading the log. Can be null if no explanation is
provided.
* @param ex This is anything that is a subclass of Throwable,
like
* Exception. Can be null for cases where there is no Throwable
event to
* report.
*/
public void logException(String explanation, Throwable ex)
{
String filename = reportDir + "/ScreenSnapshot" +
String.valueOf(shotCount++) + ".PNG";

logBlankLine();
if (explanation != null)
Reporter.log(explanation, true);

if (ex != null)
Reporter.log(throwableToString(ex), true);

if (driver == null)
{ // We may not have been able to start the session
if (selenium != null)
{ // Use this if we are using Remote Control instead of
WebDriver
String str = System.getProperty("user.dir") + "/"; //
Current dir

selenium.captureScreenshot(filename);
Reporter.log("<img src=\"file:///" + str + filename +
"\" alt=\"\"/><br />");
}
} // if
else
{ // Not all Webdriver instances can take a screenshot
WebDriver augmentedDriver = getScreenshot();
try
{
File file;
String str = System.getProperty("user.dir") + "/"; //
Current dir

file = ((TakesScreenshot)
augmentedDriver).getScreenshotAs(
OutputType.FILE);
FileUtils.copyFile(file, new File(filename));
Reporter.log("<img src=\"file:///" + str + filename +
"\" alt=\"\"/><br />");
}
catch (Throwable ex1)
{
Reporter.log("Unable to capture screentshot to " +
filename +
"<br/>Got error: " + ex1.getMessage());
} // try-catch
} // else

logBlankLine();
} // logException

Sumanth Reddy

unread,
Feb 24, 2012, 11:25:21 AM2/24/12
to seleniu...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

Zack Lemley

unread,
Feb 28, 2012, 11:30:35 AM2/28/12
to Selenium Users
I can confirm this issue. On selenium 2.19, when calling
'Augmenter.augment(driver)' an extra blank browser window is produced
every time. Also, the reference to the new browser is lost and cannot
be closed, as far as I can tell.

If there is a workaround for this, I'd love to see it. Otherwise, I
know this is an experimental class, so I'm not sure if this would be
worth adding as an issue or not.

Thoughts?

Jason Leyba

unread,
Mar 19, 2012, 1:33:18 PM3/19/12
to seleniu...@googlegroups.com

Al Fenkner

unread,
Apr 10, 2012, 7:19:29 PM4/10/12
to seleniu...@googlegroups.com
Hello Lindsay, I was running into the same issue so I worked around it by casting to RemoteWebDriver rather than using the Augmenter.  Since only drivers that support screenshots implement RemoteWebDriver this also gets around the HtmlUnitDriver problem (no screenshot allowed).  By the way, this code is implemented inside of a JUnit Rule that I wrote so if any test failure happens it will take a screenshot as long as the driver is compatible.  I cleaned out some of my own framework code to simplify it a bit:


                File screenshotFile = null;
                try {
                    // This checks to make sure we're not running an
                    // incompatible driver to take a screenshot (e.g.
                    // screenshots are not supported by the HtmlUnitDriver)

                    //the following line will throw a ClassCastException if the current driver is not a browser typed driver
                    RemoteWebDriver compatibleDriver = (RemoteWebDriver) driver;

                    screenshotFile = ((TakesScreenshot) compatibleDriver).getScreenshotAs(OutputType.FILE);
                } catch (ClassCastException e) {
                    //this driver does not support screenshots.
                    // this should get logged as a warning -- this only means the driver cannot be of type RemoteWebDriver

                } finally {
                    if (screenshotFile == null) {
                        System.out.println("This WebDriver does not support screenshots");
                        return;  //get us outa here
                    }
                }

                try {

                    String pathString = "some path of your choice"
                    File path = new File(pathString);

                    if (!path.exists())
                        path.mkdirs();
                    
                    stringPath.concat("/someFileName.png");

                    File newFileLocation = new File(pathString);
                    System.out.println("Full path to screenshot: " + newFileLocation.getAbsolutePath());

                    FileUtils.copyFile(screenshotFile, newFileLocation);
                } catch (IOException e) {
                    e.printStackTrace();
                }

I hope this helps!
-Al

Edwolb

unread,
May 23, 2012, 3:53:42 PM5/23/12
to seleniu...@googlegroups.com
This is the path that we took on this, and so far it looks like its working:

  /**
   * Helper function to ask the test class to take a picture
   * 
   * @return File pointing to a screenshot
   * @throws IOException If file could not be saved
   */
  public File takeScreenShot() throws IOException {
    WebDriver d;
    if (driver.getClass().getName().equals("org.openqa.selenium.remote.RemoteWebDriver")) {
      d = new Augmenter().augment(this.driver);
    } else {
      d = this.driver;
    }
    File srcFile = ((TakesScreenshot)d).getScreenshotAs(OutputType.FILE);
    return srcFile;

Krishnan Mahadevan

unread,
Jun 9, 2013, 11:18:32 PM6/9/13
to seleniu...@googlegroups.com
Oren,
I would attribute this behavior to a probable bug in your code. Somewhere in your test code you are creating an additional instance of WebDriver which is what is triggering the duplicate browser window. 

On Sunday, June 9, 2013, Oren Rubin wrote:
Hi,

I'm still seeing this issue in 2.31 (just tested it with ChromeDriver).
More info:
We started by casting to RemoteWebDriver, and when it failed (my client will update me on concrete type soon) I tried the Augmenter which resulted in this aforementioned manner.
Is there another option before I resort to the Wire Protocol (using REST API using session-id/server-address)?

Cheers,
Oren Rubin
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.

To post to this group, send email to seleniu...@googlegroups.com.


--
Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
Reply all
Reply to author
Forward
0 new messages