Connecting with selenium to a browser PID - selenium

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.

Related

Is there a way to get handle of already opened ChromeDriver window in another process using Selenium?

So let's imagine that I have 2 running processes.
In the 1st process I create an instance of selemium ChromeDriver, which has it's service on http://localhost:49402.
What I want to do: to use this opened window from another process, or at least to open new window / tab with environment of 1st window (cookies, session etc.).
I tried to use selemium.webdriver.Remote, and it launches a new window, but it seems to be independent from the 1st one.
Is there a way to do what I want?

Reuse existing firefox instance with selenium and capybara

currently during debug of test cases selenium is opening a new firefox window, in whatever desktop screen it chooses. I want to be able to have selenium attach to the existing window (and not close the window when the test is over.)
I see this in the selenium documentation
webdriver.firefox.useExisting Never use in production Use a running instance of firefox if one is present
but I do not see how to set it from rails/rspec/capybara
I have looked at the related SO answers, and they are more to do with attaching to a running test. I just want to control where the window is, and be able have the window open with the developer console, so we can see what is going on, and finally have the window stay open at the end of the test
Depends on the issue 2163 it was a feature of Selenium 1 and not implemented to Selenium 2 but still stays in documentation. Check this issue.

How do I open a new private window in Selenium IDE and switch between windows?

I'm trying to make automated tests for a site, using Selenium IDE (not Selenium Server, RC, 2.0, and WebDriver).
I want to be logged in with user 1 in Firefox window 1 and open a Firefox private window to sign in with user 2. I need this because the website I want to test doesn't allow multiple users signed in in the same browser at the same time.
So:
1) Is there a way to open a private/incognito window?
2) How do I then switch back to the main window?
Here's how switching between simple windows looks like:
http://i.stack.imgur.com/P5bbt.png
In the attached image you can see how I solved the problem:
It works fine with Firefox version 42.0 (and earlier versions). With Firefox 43 I have some problems because "openWindow screen2" does not overwrite my window I open with javascript but opens an own window. I'm looking for a solution for this issue.
As far as I'm aware this isn't something that Selenium IDE can do. The best solution I can think of would be to use something like Autohotkey and combine the it with Selenium.
With AHK you can set a script to mimic the keyboard command to open a private window (ctrl+shift+p). When I've used it with selenium in the past I've set the AHK script to start when it detects a certain window title, and then had selenium call a javascript function from the user-extensions to amend the title of the page you're on to the title which will trigger the function when you need the AHK script to run. (Best not to use the default one, otherwise you could end up with countless private windows if it hits that page multiple times).
Try this,
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("browser.private.browsing.autostart",true);

screen resolution in mode "Run whether user is logged on or not", in windows task scheduler

I am using Python 2.7 and Selenium 2.39.0. to test a web application. When I run my test as a Windows (7 Ent.) scheduled task with the option "Run whether user is logged on or not", it looks like the screen resolution or window sizing changes; Some buttons become hidden behind the toolbar at the bottom of the browser window and therefore, it can't be clicked by Selenium.
I don't have this problem if I choose the option "Run only when user is logged on"; even if the screen is locked, the buttons are visible and clickable.
According to the Windows task properties, it is using the same user account.
Is there a way, browser setting or a registry key which can help to keep the same resolution and size in both modes?
I know I can scroll down the page, but I am trying to understand and may be prevent this difference of behavior between these two modes.
I've had the same problem. I tried all registry keys I could find, disabled TMM, but to no avail.
Running Selenium with a user logged in seems the only way Windows 7 will give you another resolution than 1024x768. So I ended up setting my Selenium virtual machine like that: have a user log in automatically on startup and launch the Selenium node after that.
In you selenium test, you can call driver.manage().window().setSize(new Dimension(1920, 1080));
Even if you screen resoltuion is 1024/768 you browser will have the correct window size and you buttons will display just fine.
You can also run your window task with user "SYSTEM". So you don't need to worry about opening the user session.
In case anyone comes to this post still looking for the answer as I did.
If you set up the ChromeDriver to run in headless mode using options you can force it to a resolution you want whether the user is logged in or not.
See below which was originally posted by #bunkerdrive in answer to this question:
What is the default window size when running Selenium tests over Azure Pipelines?
Code is C# but I imagine there is a python equivalent to add the options.
var options = new ChromeOptions();
options.AddArguments(new List<string>()
{
"--headless",
"--disable-gpu",
"--no-first-run",
"--no-default-browser-check",
"--ignore-certificate-errors",
"--no-sandbox",
"--window-size=1920,1080",
"--start-maximized",
"--disable-dev-shm-usage",
});
driver = new ChromeDriver(options);

How to maintain session in selenium while opening new window

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.