IE full Screen mode using selenium Webdriver - c#

I want to check if Internet Explorer window is in fullscreen mode or not?
I use driver.Manage().Window.Maximize();
It maximizes window only but does not switched to FullScreen view.
Is there any method?

Selenium web driver do not have the API to achieve the Full screen as per your post. But you can achieve it through send keys method of windows. Try below code.
System.Windows.Forms.SendKeys.SendWait("{F11}");

#Sham: that is a unique way to do it... I would recommend this:
driver.Manage().Window().Maximize(); after window braces should be added

Related

Keep selenium out of focus for user

I am using selenium in C#. I am curious if there is a way I can make it so that as a user you can still do what it is you are doing without being interrupted by selenium. For example, if I am typing something and selenium opens a new tab, my mouse focuses on the tab it opened and doesn't allow me to type unless I click on where I am typing again. Would this be something to do in code or in windows settings?
Run browser in headless mode , in this case the browser runs without GUI so there won't be any interruption
All browsers support headless flag now , add headless argument to capabilities while creating the browser instance
Previously headless browsers like phantomjs used to use webkit rendering engine but now chrome has inbuild headless support and uses same rendering enginee blink
so there is no effect of quality
You can run in headless mode.
Basically in headless mode as name sounds, there's no windows. You do not even need browser in your system.
Code:
var chromeOptions = new ChromeOptions();
chromeOptions.AddArgument("--headless");
chromeOptions.addArguments("window-size=1920,1080");

How to select a window through Selenium and C#

I am looking to write a simple selenium test that will find a window with a title or URL and then select it, then select swap tabs once. I have tried using various things like
driver.SwitchTo().Window(handle);
I have managed to write this function in Powershell, but because I cannot identify the Chrome window with Powershell I read that Selenium was the best way to go. I am using Visual Studio and have installed all the Chrome Drivers and everything.
No, you can't locate a window with a specific title or URL and then use it to switch tabs.
Driver.SwitchTo().Window(windowHandle)
The current top-level browsing context is represented in the protocol by its associated window handle. A top-level browsing context can be selected using the Switch To Window command as follows :
driver.SwitchTo().Window(windowHandle);
You can find a detailed discussion in What is the difference between WebDriver.SwitchTo().Window() and WebDriver.SwitchTo().Frame()

Selenium ChromeDriver - Run in background but not headless

I am looking for a way to run selenium tests with a chrome driver, in the background. With the background I mean as in, not the foreground focussed window. I can actually do this, but as soon as actions like opening a new tab or switching between windows (so basically switching window handles) happen in the chrome driver, the browser window gets pushed to the foreground.
So my question is, how can I prevent this from happening without running the test headless?
Any suggestions are appreciated, open for discussion.
EDIT
As a somewhat temporary solution I came up with the following.
Using the Windows 10 Virtual Desktops feature, I run the test and thus the chrome browser window in a seperate virual desktop.
I then switch back to my main virtual desktop to continue with other tasks.
This prevents the chrome browser window from being forced to the foreground.
Note that this still makes a flashing chrome icon appear in the taskbar when any of the actions described above appear.
Still looking for a more solid solution, so any suggestions are still appreaciated.
To hopefully open new perspectives and discussion points, and ultimately a solution, I will provide some more detailed info of what my code is doing.
I have 5 chrome webdrivers, and each of these webdrivers contains 6 tabs (WindowHandles).
The idea is that a certain process has to be repeated continuously on each tab. So we loop over each webdriver, and within that webdriver over each tab and set this tab as the webdrivers current WindowHandle. This makes the chrome window visibly switch to the assigned tab.
After that switch has taken place, so basic selenium automation is performed on the content of the tab, after wich we repeat the whole process.
The actual issue seems to take place when a chrome webdriver switches to a new tab (WindowHandle), at this moment the chrome window containing the tab is pushed to the foreground and steals focus. Note that this does not always takes place, often it can switch tabs without any issues. So it is unclear wether there is another factor which would cause the window to steal focus.
EDIT 2
After doing the following:
I overloaded the selenium method which is used to switch between tabs (WindowHandles), and called SetWindoPos each time. Unfortunately this did not solve this issue either. I will try to look deeper into what might be causing this and will report back. – S. Van den Wyngaert
I went out for a few hours while running the tests, and came back to see that surprisingly I was still on my main Virtual Desktop (win10 feature). This means that the issue didn't occur during the time I was gone. I started working again, opened a chrome window and noticed that shortly after I did this, focus was stolen by one of the chrome driver's windows again.
What I conclude from this is that the issue only occurs when another chrome window (not opened by a chrome driver from code) is opened.
I will keep investigating and will report back with updates.
After investigating this behavior for a few more hours I noticed that when another chrome window is open, as long as this has focus, the issue doesn't take place. So to quickly summarize this:
The issue doesn't take place when:
No other chrome windows (not selenium driven) are opened or minimised
Another chrome window (not selenium driven) is opened and has focus
Another application running fullscreen mode has focus
The issue does take place when:
Another chrome window (not selenium driven) is opened and has no focus
Note that when I talk about another chrome window I specificly mean a chrome window that is not driven by selenium, so a regular chrome window opened by the user.
Easiest way would be to run a local selenium grid. Start your node(s) as a windows service. This way the test will run in the background, without being headless.
Another good option to scale your solution, and if your machine has the capacity to run docker, is to use
zalenium
It's a docker based, auto scaling, selenium-grid solution that works pretty quick out of the box.
You can watch your tests live via the management pages, watch a recording after the fact, pause/debug with live interaction via VNC. Also something to be said for not having the worry about changing browser versions.
Last time i used it, it had the odd bug and throws an end of stream error every now and then - but that was a good year ago.

Display IE in full screen mode but show taskbar

I use C# to run IE browser by code
new InternetExplorer();
I want IE runs in full screen mode, and I also want the taskbar shows at the bottom of IE instead of covering the bottom.
Can someone tell me how to do?
The simplest way using Process.Start() with command line parameter
-k :Starts Internet Explorer in kiosk mode
System.Diagnostics.Process.Start("iexplore.exe"," -k http://google.com");

WatiN - Set the position of a browser

Im testing my website using WatiN , and for a specific test I'm opening few IE windows and work on them simultaneously.The problem is that the windows are opened in the same position and i can't see what is going on inside the windows. Any ideas?
I'm looking for something like:
var browser=new IE();
browser.SetPosition(top_left_X,top_left_Y);
Swapping between windows
To bring one of the browsers to the front use the browser BringToFront() method.
Like:
IE ie = new IE();
ie.GoTo("www.cnn.com");
IE secondIE = new IE();
secondIE.GoTo("www.google.com");
secondIE.BringToFront();
Resizing windows
To resize the windows and make them both viewable, say side by side, I believe you'll need to use something like SetWindowPos() or PInvoke's movewindow(). You can use ie.hWnd to get the window pointer to the browser. Unfortunately it has been a really long time since I've done anything like that and can't put together an example now, or even guarantee it is the right course of action.

Categories