I am trying to open chrome, close it and then open it again using the same session.
Is a thing like this even possible? I've looked through the internet/stackoverflow and tried using driver.Close(); but with no luck.
Anybody has some experience with this and mind helping me?
thanks
In Selenium Webdriver, a browser session can be closed using two webdriver commands: close() and quit(). The situations in which they are used are briefly explained below:
close() is a webdriver command which closes the browser window which is currently in focus.
During the automation process, if there are more than one browser window opened, then the close() command will close only the current browser window which is having focus at that time. The remaining browser windows will not be closed. The following code can be used to close the current browser window:
driver.close() //where, ‘driver’ is the Webdriver object.
quit() is a webdriver command which calls the driver.dispose method, which in turn closes all the browser windows and terminates the WebDriver session.
If we do not use quit() at the end of program, the WebDriver session will not be closed properly and the files will not be cleared off memory. This may result in memory leak errors.
The following code can be used to close all the browser windows:
driver.quit() //where, ‘driver’ is the Webdriver object.
If the Automation process opens only a single browser window, the close() and quit() commands work in the same way. Both will differ in their functionality when there are more than one browser window opened during Automation.
Source: Reference link
Related
Here's our routine driver instantiation code
WebDriver driver =new InternetExplorerDriver();
driver.get("http://internal.com");
Let's say that the above opens an instance (window) of IE - Window 1. In this case, we have some JS on internal.com's index.html that opens a new window, say Window 2. The problem is that when we quit the driver, we can easily close Window 1 but we seem to have no control over Window 2.
driver.quit();
Are there any clean ways to close Window 2 and any other derivative browser windows at the end of every test case?
I am creating automated test cases with Selenium WebDriver 2. My code is set up, so that FireBug automatically is opened when Selenium WebDriver opens FireFox. A few seconds later I ask Selenium to close it again. For some reason, if I don't do this, sometimes FireBug won't be available to me at a later stage.
My problem:
When I use the TestNG suite to run my test suite, some of the test cases end up opening FireBug but not closing it again. My guess is, that this is due to existing browser windows already being open. The "close FireBug code" is then misused to open FireBug instead of closing it.
For this reason, I would like to make a check to see if FireBug is open, and if so, I would like to close it.
Opening code:
String firebugPath = TO_Constant.fireBug();
FirefoxProfile profile = new FirefoxProfile();
profile.addExtension(new File(firebugPath));
profile.setPreference("extensions.firebug.showFirstRunPage", false);
profile.setPreference("extensions.firebug.allPagesActivation", "on");
driver = new FirefoxDriver(profile);
Code to close FireBug:
Actions action = new Actions(driver);
action.sendKeys(Keys.F12).build().perform();
I can find ways to do this in javascript, using window.console. Is there any way to do something similar in java?
console.log('is DevTools open?', window.devtools.open);
You can also listen to an event:
window.addEventListener('devtoolschange', function (e) {
console.log('is DevTools open?', e.detail.open);
});
It doesn't work when DevTools is undocked. However, works with the Chrome/Safari/Firefox DevTools and Firebug.
The answer is by Sindre Sorhus and has been taken from here!
Find out whether Chrome console is open
I am opening a window based application in my desktop using Sikuli. After clicking on a button in that application, a browser is opened.
Can I get focus on that browser in Selenium? Can Webdriver detect an already opened browser?
The answer to that is no. In order for Selenium Webdriver to control a browser it must be instantiated as WebDriver object creating a session ID, etc..
One possible solution might be to somehow intercept the URL that is generated by the desktop application and use it to launch a Webdriver instance.
I'm new in Selenium. I'm using FirefoxDriver(). So, basically when i run my program. It opens an external firefox browser, So when i close that firefox browser. my program terminates and says Error communicating with the remote browser. It may have died.
But How to make my program run, After closing browser it should suppose to run and show on console program? Is that possible? Please let me know.
Surely, help would be appreciated!
Try WebDriver driver = new HtmlUnitDriver();.
This does not open any external browser.
Currently I have the following issue:
my code is
WebDriver driver = new ChromeDriver();
driver.close();
But thoissometimes ens in an error.
Try using driver.quit(); Do not use close();
Actually, this is problem, especially if you are using Chrome. Try also sing Firefox.
Add driver.quit() to an #AfterClass method
Close will shut the current active window and if it is the last window will then perform a quit(), it does however need to have a valid active session to be able to do this.
If your test has failed that session is probably dead, so when you call a close it doesn't know where to send the command and doesn't do anything.
Quit will shut down all clients if there are no active sessions so if you send a quit and have no active sessions it will just clean up