RE: [selenium-users] Selenium open new browser instead of new window

2,404 views
Skip to first unread message

Peter Gale

unread,
Sep 7, 2012, 6:21:01 PM9/7/12
to Selenium Users
It sounds like your scripts are instantiating a new driver object rather than re-using an existing driver object. We'd have to disprove this to be the case before trying to consider other options (and I can't think of any other possibilities yet).

If you can't see for your yourself how a new object is instantiated, we'd need to see a set of code which exhibits this behavior to help further ... if you can reduce it to a minimum that would help us get straight to the heart of the problem.


Date: Fri, 7 Sep 2012 11:27:16 -0700
From: jie...@funsockets.com
To: seleniu...@googlegroups.com
Subject: [selenium-users] Selenium open new browser instead of new window

Hi 

I'm new to selenium webdriver, I'm trying to do some tests on our website, but when I use driver.get(url), it always opens a new browser instead of a new window, and the new browser doesn't have the username and password I saved in my main browser, so it can not open the page. Any idea of this? How can I just open a new window in stead of a new browser?

Thanks a lot!

--
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.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/4sF97_bjjtAJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Manoj Hans

unread,
Sep 8, 2012, 3:43:04 AM9/8/12
to seleniu...@googlegroups.com
I think peter he is talking about existing browser.

for ex-- He opened a browser manually and want to open the site in the same browser which is not possible.



--Manoj Hans

On Saturday, September 8, 2012 4:11:56 AM UTC+5:30, jpan wrote:
Thanks Peter, here is the code, I changed the url to goole due to our site is not public yet, every time I ran this code, it will brings up a new browser in stead of a new window in my current browser :

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

public class testcode {

        public static void main(String[] args) {

        WebDriver d2 =new FirefoxDriver();

         d2.get ("http://www.google.com");

Peter Gale

unread,
Sep 8, 2012, 6:11:22 AM9/8/12
to Selenium Users
JPan

I guess was presuming you meant that one of your automated tests opened a browser and that you were expecting a second test to reuse the same browser. Is that not the case?

If not, and you are expecting to open a browser manually, logging on to a site and then have the automated test carry on from where you started it manually? As Manoj says, you can't do that, at least not with Firefox (IE or chrome might act slightly be differently).

You could, however, have your script start a new browser session, then set your program to wait while you log in manually, either for a fixed length of time or until a specific post-login element has appeared.

Alternatively, using Firefox, you can create a stored profile and open it manually to log on to the particular site ... if you select the "save my password" option the same profile should should not ask you for credentials when you go in through the same profile with your WebDriver based program.

But most people want to bypass any need for manual intervention or pre-test preparation, and are quite happy to have their automated scripts type a user name and password in for them ... you can always read the credentials from a secure file specific to the current PC user if you are worried about hardcoding personal passwords inside group programs.


Date: Sat, 8 Sep 2012 00:43:04 -0700
From: hman...@gmail.com
To: seleniu...@googlegroups.com
Subject: Re: [selenium-users] Selenium open new browser instead of new window
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/honrISlSA0YJ.

jpan

unread,
Sep 9, 2012, 1:43:28 AM9/9/12
to seleniu...@googlegroups.com
Hi Peter and Manoj,

Thanks a lot!

Just want to confirm one more thing:

I manually opened a Firefox browser A, and I selected 'save the password', then I ran the code above to open a google page, it  bought up another Firefox browser B, which is not a new window of A, and the 'save the password' option is not selected. For me, it looks like whatever I set up on my firefox browser will not apply to the new browser the code brings to me. Is this true?

Pankaj Dhapola

unread,
Sep 9, 2012, 3:53:12 AM9/9/12
to seleniu...@googlegroups.com

:) Man . . . . .

I thought your code "d2.get ("http://www.google.com");" opens a new browser.

Whenever you run a code like "new FirefoxDriver()" this will create an object representing Firefox browser and each time you instantiate a new Firefox Browser, each object of Firefox browser is independent to work with. I think a new Firefox profile (by default) will be created for each instantiation of "FirefoxDriver" class, unless and until you instantiate a "FirefoxProfile" class and supply an argument to "FirefoxDriver" class constructor. Big guns out here in this group will definitely let you know more in details.

Warm Regards

Pankaj

Peter Gale

unread,
Sep 10, 2012, 3:51:41 AM9/10/12
to Selenium Users
Yes ... WebDriver's Firefox driver by default will open a completely new and clean instance of Firefox, unless you tell it to open with an existing named profile.

If you work with a  saved profile, any changes you make manually to the profile (such as saved cookies for usernames/passwords) will affect the Firefox browser instance opened by WebDriver.

If you search the forum for "Firefox saved profile" you should find a description of how to work with a saved profile in code.


Date: Sat, 8 Sep 2012 22:43:28 -0700
From: jie...@funsockets.com
To: seleniu...@googlegroups.com
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/izFnk7xlRFEJ.
Message has been deleted

Peter Gale

unread,
Sep 10, 2012, 5:06:23 AM9/10/12
to Selenium Users
Jpan's issue related to the use of WebDriver, not Selenium IDE, you your's is not the same issue. Please start a new thread.


Date: Mon, 10 Sep 2012 02:00:31 -0700
From: moha...@gmail.com

To: seleniu...@googlegroups.com
Subject: Re: [selenium-users] Selenium open new browser instead of new window

Hi,
My issue sounds relevant to this topic.
"Opening the new browser in S-IDE" is the task (may be this is a issue for jpan, this is wt i wanted to do)

or

automate close and reopening browser window in S-IDE.
Scenario:
a. User logins to the application.
b. Closes window - without loggin out.
c. Now open the browser - to verify whether user logged in our not.
Thanks in Advance,
Amar
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/WMWQQPrPJlMJ.

jpan

unread,
Sep 10, 2012, 1:50:55 PM9/10/12
to seleniu...@googlegroups.com
Thanks Pankaj for the confirmation, it seems I have to figure out a way to work around this.

Peter and Manoj, thanks for your help.

Amar, when I use IDE, it will only open a new window in current browser, will not bring up a new browser.

Jie

Peter Gale

unread,
Sep 10, 2012, 1:54:01 PM9/10/12
to Selenium Users
Selenium WebDriver is not an updated version of Selenium IDE, so don't expect it to work the same way - it is  a completely different product, you have to learn how it works and work with it.


Date: Mon, 10 Sep 2012 10:50:55 -0700
From: jie...@funsockets.com
To: seleniu...@googlegroups.com
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/PpKizajRYKgJ.

Pankaj Dhapola

unread,
Sep 12, 2012, 12:57:55 PM9/12/12
to seleniu...@googlegroups.com
Your welcome Jie.
As Peter said, make it a point that Selenium IDE and Selenium WebDriver are different in architecture. Selenium WebDriver is purely based on how well you code your Test cases without support of Record and Run which ultimately gives you a flexibility and good understanding of what you are coding.

:)

Thanks
Pankaj
Reply all
Reply to author
Forward
0 new messages