How to maintain session in selenium while opening new window. I am clicking a download button after which a file should be asked to download(IE). But running via selenium it opens a new window asking again to login???
I had similar issues. I don't know your implementation, but maybe you're cleaning cache with each new browser Instance. Try to find why it's opening new Window instead of using same browser instance and just open it's download_window. How you handle default_window can also be the answer you are looking for.
Related
I am using Edge (in IE mode) to run a test. For quite a while we have been having a problem when we click on one link and a new Edge window comes up, selenium cannot find the new Window handle. We have had to use something like Test Complete to access the window. (We can't use Robot as that does not work on Jenkins).
I looked at the task manager, and after the click there is a new msedge.exe task (in this instance PID 14328 but that will change each time).
I want to open a new Edge browser (with a new driver) and see whether I can attach to that Edge browser using the PID. I have a feeling this may work?
I found this:
Can Selenium interact with an existing browser session?
but this does not mention anything about a pid. It seems you open a new driver and get the session id of the driver, and the url, and set it back. I want to be able to connect to a new PID. I am hoping this may be able to solve the problem, but I am not sure. Is there a way to do this?
I am doing this with Java via Eclipse.
I work with Excel VBA Selenium under Windows 10.
I want to access a Chrome window that has previously been opened by another app and of whose name only the first part is known, the rest is a code that changes each time it is created. It is open together with other tabs in the active Chrome browser.
In order to start Chrome with Selenium, all I know to do is
Set dr = New ChromeDriver
This creates an Object "dr". When I look up the properties of dr, the property "Windows" shows the value
"BrowserNotStartedError / Browser not started. Call Get, Start or StartRemotely first."
Start or get both create a new Chrome instance which does not allow me to access windows in the already open instance.
I tried to use this code without "New", but this does not work.
I have not found any hint on how to work on the existing instance of Chrome. Is it possible at all?
If not, how else could I access any existing window? The URL is unique and can only be created by the 3rd party app for security reasons. If I try to copy the URL to the new Chrome instance I get an authentication error, so this is not an option.
This web page basically contains a menu that allows me to download certain data safely, which I want to automate.
Any help is appreciated.
Actually, there is a way to do it with Selenium driver for Chrome.
Locate your chrome.exe directory and copy and append the line below into the target bar.
--remote-debugging-port=9222 (Include the preceding space).
Then copy the following code into a vba module, execute it, and it will allow you to manipulate the existing chrome session that you created.
Dim chromeBrowser As Selenium.ChromeDriver
Sub existingChromeSession()
Set chromeBrowser = New Selenium.ChromeDriver
chromeBrowser.SetCapability "debuggerAddress", "localhost:9222"
chromebrowser.Get("https://www.google.com")
End Sub
My question has been resolved.
With a Selenium driver for Chrome, it is not possible to access Chrome tabs that have not been created with Selenium.
According to QHarr, it could be done by using shell/internet explorer to grab a handle on existing IE windows. In this case, of course, the app would have to create the HTML file with IE, i.e. the default browser would have to be IE.
I am writing a test that verifies that a warning to the user before the user opens a document. If the user says that they still would like to open the document, the document opens in an external application (pdf or word).
But now I have an external application over the browser window, and it messes up for other tests.
So, what are the best practices around this kind of issue? Rewrite of the appliction to allow for not opening documents in test?
Added description:
The problem is twofold.
1) It starts processes (word and acrobat) that fills the desctop and requires resources from the test-slave
2) The external process seems to interfer with other tests since (guessing here) it is located over the browser window.
what i understood from your post is, the document(word/pdf) is opening in the browser window hence you are not able to proceed with further steps. If so, you can verify the Title to make sure the document is opened in browser window and can navigate back using below snippet.
driver.navigate().back();
Hope this helps.
What I understand from the line
'But now I have an external application over the browser window, and it messes up for other tests.'
is that once user clicks on open button a new window opens up (Window based application) since you have mentioned PDF or Word.
You can use robot class in such cases, below code snippet will close the current active window:
Robot rbt = new Robot();
rbt.keyPress(KeyEvent.VK_ALT);
rbt.keyPress(KeyEvent.VK_F4);
rbt.keyRelease(KeyEvent.VK_ALT);
rbt.keyRelease(KeyEvent.VK_F4);
Make sure you deal with sync issues properly so that intended window is closed instead of AUT.
I'm using the Selenium Client drivers to run tests built in C#. I'm having a problem where the test navigates to a page and clicks on a button in a form with its target set to _blank causing it to open a new window. However the new page being opened returns an XML document and not a typical webpage. Selenium seems to have trouble with this because it hangs when the button is click and the new window opens. No instructions after the click method are executed. The test eventually fails with the error Timed out running command.
Any help/guidance would be appreciated. I've scoured the net but haven't seen anyone running into this particular issue of the page being opened not being a typical webpage which I think is the core of the problem as Selenium can't really manipulate this new opened window. I would post code except that literally all I'm doing is calling the click method on a button which causes a new window to open. Thanks in advance.
To tackle the issue of opening in new window. I typically get url of the link which is to be opened and instead of using selenium.click(), I use:
selenium.open("http://yourwebsite/yourlink")
This helps me to be on the same window only(which avoids opening new window or tab) and when the testing is finished on this page and you want to switch back to original page you can again use:
selenium.open("http://whatever/")
js gets downloaded to browser cache.
js contains functionA that constructs the url and calls the window.Open to open the url.
i call the functionA to open the window.
selenium doesnt detect the window at all. i did getAllWindowTitles and getAllWindowNames, etc. But do not see window at all.
by the way the reason i had to this is because when i click on button that has an onclick='calltofunction()', the window is not detected either.
it would be better actually if i can force selenium to see the open window after i click the button.
Thanks!
The straight forward answer that I can think of right now is to move on to Selenium 2.31.0, which has an updated support for WebDriver, and can be used in parallel to Selenium.
Then, it is easy to do ALT+TAB (for Windows, or CTRL+TAB for tabs), and WebDriver picks up the new tab/window and reads off of it.