Switch to window (tab) without bringing browser to front - python-3.x

I am using Python and Selenium to navigate multiple tabs. How can I switch to a different window/tab without bringing the entire browser window to the front and without the selenium window "stealing" the focus of my computer? For example, if I'm typing in the search bar of a normal browser and my script switches tabs, it'll stop typing the search bar and I'll have to reclick the search bar to start typing again.
No headless mode suggestions please.
Changing the browser location off the screen doesn't work because it still steals focus
Minimizing the browser doesn't work because it unminimizes when the switch to command is run
Here is how I'm switching windows:
for handle in driver.window_handles:
driver.switch_to.window(handle)

The answer is NO, this is not possible to do with Selenium.
Selenium is created to simulate actions a user can do via GUI.
As a user you can't do what you are asking about, Selenium can't do it as well.

I think, If you deploy your Automation scripts to a VM (which is there in you Machine), You can continue to start working on your local browser and Your Automation script will run on a VM and will have a independent environment for the same.

Related

Handling file download popup of chromium browsers using VBA

I'm using Selenium with VBA and Microsoft Edge to collect information, and download some files from a webpage. Everything works great except for the downloading part.
On this example site: https://file-examples.com/index.php/sample-documents-download/sample-doc-download/, Code like
oWebDriver.FindElementByXPath("//a[#href=""https://file-examples-com.github.io/uploads/2017/02/file-sample_100kB.doc""]").Click
will result in a popup like this:
Unfortunately, it is not possible to simply change the browser's preferences in my case, because the macro will be running on a machine with limited authorization and the following setting can not be changed:
The last option can be translated to: "Ask for the storage location with every download" and it is locked.
It seems that the "Save As" popup in the first screenshot can't be accessed, neither with Selenium nor with SendKeys.
So the only option seems to be using the Windows API with VBA to somehow automate this step, however, even so, it seems to be impossible to get a handle on this pesky popup. I tried finding the window with Spy++ and it doesn't seem to show up as a separate window:
The only solution I can now think of is getting the window size of the parent Edge browser window, navigating the mouse to the approximate position of the "Save As" button, and clicking it there using VBA and the Windows API. Obviously, This is not a great solution, as it would be quite frail and can easily break with the smallest misalignment.
Is there any other way to automate this step that doesn't require moving the mouse and automating the "manual" clicking, using only VBA with Selenium?
Selenium only works for browser web page automation. The pop-up is not a part of the wab page so Selenium will not be able to recognize it.
And I think any setting in Selenium including "download.prompt_for_download" won't have effect. The pop-up is controlled by the browser setting, and the browser setting is controlled by your group policy, you can't override it with Selenium settings.
I think the only way is to use some 3rd party UI automation library to click that option along with Selenium, just like what you said in the question.

Script solution for tabs in bash wanted

i'm in search for a solution for the following situation:
I am working for a customer who only allows accessing the linux servers
by putty (from a Windows Terminal Server).
Unfortunately i need multiple Session to work properly and effective.
Tmux and Screen are not a good option for me, because i need a visual
"tab" to keep track of all the stuff im doing.
Is this even possible or am i lost here?
Best regards.
MremoteNG does tabs and uses Putty (Putty comes with it). If you have RDP or console access to Windows server, you can upload MremoteNG portable.
Perfectly possible in screen: How to open tabs windows in GNU screen – DevSolar
Perfectly solved my problem! Thanks DevSolar!
If you're using PuTTY, you can simply open two sessions at once. Open your first session, then right-click on the PuTTY icon in your taskbar, click "PuTTY" from the context menu, and it'll open a new instance of the program. Unfortunately, this won't result in a second tab, but instead it will result in a second window and you can swap back and forth between windows.
Other SSH clients do have actual tabs as a feature - one example is MobaXTerm, which is free and doesn't require admin privileges to use on your computer, and which is indeed tabbed. It can also import your existing PuTTY configurations, so setting it up is pretty quick.
You can get this application that allows you to have mulptiple tabs in putty. you dont need to "install" it so your lack of permissions wont be an issue :
http://ttyplus.com/multi-tabbed-putty/
Regarding your auth issue, I would recommend read this :
https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2
Note - Dont worry about being lost, everybody learns at different speeds.
Regards!

How Mirror webpages as Web Video Wall into another browser?

We have a video wall with some monitors. each one is plugged into a Raspberry PI 3.
Mostly we just are showing webpages into the video wall (reports, status etc)
Today we control the content of each raspberry using VNC. I was wondering if is there a web service or plugin that allows me to just configure the URL that I wish to show on each screen. Plus, Sometimes we split the each screen into 2 or more webpages.
Is there any web app, chrome plugin or web service that allows me do that?
Thanks
OBS, I don't know if here is the right place to this kind of question. If is there another community where i could ask this, i will be glad to know.
I can not give a complete and exhaustive answer, since you do not provide any description of how it should look and how you want to control it.
Let's start with the fact that almost every browser at startup you can specify URL and start the browser like this:
# firefox https://google.com
Then the browser opens with the page you need.
To close the page, you can kill the browser with a command like this
# killall firefox
You can run commands on the Raspberry PI using ssh, it's much easier than running the VNC session.
Most likely you may encounter a problem when you receive a message stating that the browser can not connect to the display. This is easily correctable with something like:
# export DISPLAY=:0
In order for the browser to always be in full-screen mode and not to lose its settings, you can configure it correctly, close all the tabs and save its configuration from ~/.mozilla/ (for firefox), and then restore it from backup every time you start it.

How To Hide Chrome Web Driver Icon (Python-Selenium)

UPDATED WITH REASONING
Goal: Run chrome web driver in background without showing an app icon in the dock or application bar. FYI: I can already run chrome headless, but I have not been able to hide or not show the chrome icon in my app bar.
Reason: I am building an application that accesses various websites in parallel and I would not like the chrome app icons to display for the synchronous tasks that are taking place. I want to run these tasks in the background.
Current Code with chrome options that will display headless chrome
chrome_options = Options()
chrome_options.add_argument('headless')
chrome_options.add_argument('window-size=1200x600')
driver = webdriver.Chrome(executable_path=executable_text, chrome_options=chrome_options)
Research
list of chrome options: https://peter.sh/experiments/chromium-command-line-switches/
one of many posts explaining how to do headless chrome: Selenium - chrome Driver fail to start in background (without a start-up window)
How can I hide the chromedriver app icons from displaying? Is there a chrome option I can set in addition to setting the 'headless' chrome option? Is this more of an OS setting that needs to be made to run chromedriver in the background? I am successfully able to run multiple chromedrivers in headless mode but it would be nice to NOT show the chrome icons in the dock or application tray similar to how phantomjs does not launch an app icon.
^In the image above those are the chromedrivers that run in headless mode displaying in my dock and ideally for my program I would not even want to display those icons since it is all background processing anyways.
Update (this worked for me to hide the chromedriver icons at least on my Mac):
I was not able to find a Chrome Option to accomplish hiding the chromedriver icons that appear in the dock. However, I was able to edit the Info.plist file for Chrome as part of my program to do the trick (of hiding chromedriver icons) using the LSBackgroundOnly key.
In the Info.plist for Chrome, programmatically, I entered:
<key>LSBackgroundOnly</key>
<string>1</string>
On my Mac using python3 code I used os.system to execute a terminal command using defaults to enter the LSBackgroundOnly key when the program is executing and then at the end of program execution I delete the LSBackgroundOnly key from the Info.plist.
like this:
1)
defaults write /Applications/Google\ Chrome.app/Contents/Info.plist LSBackgroundOnly -string '1'
2)
defaults delete /Applications/Google\ Chrome.app/Contents/Info.plist LSBackgroundOnly
AS INFO: This is tricky because your normal chrome app may start up in background mode if you don't add/delete LSBackgroundOnly properly during program execution. In my experience, worst case scenario you may have to manually remove LSBackgroundOnly from the Info.plist file then restart your computer to get Chrome out of background mode.
I remove the LSBackgroundOnly key from the Info.plist file in my program after program execution because the key only needs to be in the file when the chromedrivers are launched. After that I want to be able to use regular Chrome app without issues of it opening in background mode. But, if you understand your program execution and handle your exceptions, this will definitely work to hide the icons correctly and there will be nothing different in using your regular Chrome app.
Happy hacking.
This is not possible using Selenium. I don't really understand why you want to do this. Is there a real purpose, or it's just you don't want it to show? Even if the Chrome app shows on the dock, in headless mode, it works pretty good.
However, if you want your icon to not appear in the dock when opened, then you need to disable it by modifying the Info.plist file for that application.
In your Info.plist for Chrome, add this
<key>LSUIElement</key>
<true/>
This will prevent your app icon from appearing in dock, when working. I found this out a long time ago and this is the post where I saw it.
PS - I have not tested it for Chrome app. Please test at your own peril.

Kiosk Mode - Browser Full Screen - Restrict everything else except the opened window

I am working on asp.net application which is used in one specific machine. On launching this website, the website will be opened in full screen. Now, I should restrict user to use only this window. I should not allow user to open any window, app, anything else by keyboard, mouse.
Please help me in designing this.
Thanks,
Fayaz
Some trial and error helped me. Posting here so that would be helpful for who are looking for same...
Quoting from http://www.pcmag.com/article2/0,2817,1858713,00.asp
You can lock down these subversive key combinations using restrictions in the Registry. Launch RegEdit from the Start menu's Run dialog; navigate to HKEY_LOCAL_MACHINE\SOFTWARE\
Policies\Microsoft Internet Explorer\Restrictions; and find or create each of the following DWORD values, setting its data to 1 to enable the restriction:
NoBrowserClose (disables closing the browser window)
NoBrowserContextMenu (disables right-click context menu)
NoFileOpen (disables use of Ctrl-O or Ctrl-L to launch an arbitrary URL)
NoOpenInNewWnd (disables opening a link in a new window via Ctrl-N or Shift-click)
And below url helps in blocking other functionality
http://blogs.technet.com/b/askpfeplat/archive/2013/10/28/how-to-setup-assigned-access-in-windows-8-1-kiosk-mode.aspx

Resources