2

I am using Selenium to open a web site, login and copy some information from one web site. However it is happening on my work station and have a display monitor.

my IT team wants to move this process to a virtual server which does not have a monitor.

1.Will this work - even if we install Chrome of Firefox on the server 2. Can we Chrome - headless to make this happen 3. Any other way - we can think of using Xserver

Please let me know.

Geo V
  • 121
  • 1
  • 10
  • No, you don't need a monitor for what you want. No, you don't need to use headless in your scenario. 3. You can use VMWare, VirtualBox and a plethora of other options, but you should consider hiring a VPS might be cheaper than you think, and to view what is going on in your VPS / VM you can simple use the well known tools like Remote Desktop(comes with windows), AnyDesk, TeamViewer, etc... – Prix Oct 10 '19 at 18:58
  • Selenium is a test-automation tool. If you are just trying to "copy some information from one web site" there are much simpler ways to do this. For example have a look at [tag:curl]. – SiKing Oct 10 '19 at 19:22
  • Being part of the said "IT" I started with the exact opposite: with a headless browser running in containers on server-side. Then within a week Business users came asking for the "headed" browser to be able to debug unexpected content their browser displays, which they could not decipher from HTML alone... – mirekphd Jul 22 '23 at 11:32

2 Answers2

1

Chrome headless should solve your problem here -- I've done this in the past with some of my automation and had success.

Just remember to use ChromeOptions to add the --headless=new flag (latest upgraded version of the old --headless flag (see docs).

You may need to tweak some other ChromeOptions as well - I also had to add --disable-gpu and --window-size=1920,1200 to get mine working just right.

CEH
  • 5,701
  • 2
  • 16
  • 40
  • I will try with --headless flag – Geo V Oct 10 '19 at 19:03
  • I did not downvote. Why does the entire Internet insist on using `--headless` flag, instead of just `chromeOptions.setHeadless(true)`, which keeps of track of anything else you *might* need like `--disable-gpu`? – SiKing Oct 10 '19 at 19:28
  • This is not supported syntax in C#, and I'm not sure if it's supported in Python either. Adding `--headless` argument is a language agnostic solution, which is why I prefer it. Good point on `setHeadless(true)` though -- if your preferred coding language supports this option, then it's a good route too. – CEH Oct 10 '19 at 20:23
1

No . To run your script you don't need to have monitor. You can access your virtual machine through remote connection and you can start the execution from that machine. Once the execution started, you can close the remote desktop session and execution will continue to run on remote machine or virtual server.

I hope this helps. Please let me know if you have any further questions.

1.Will this work - even if we install Chrome or Firefox on the server - Yes it will work

2.Can we Chrome - headless to make this happen - If you are going to use virtual server just for execution,then you don't need to run in headless mode. Headless execution is needed for environments where you don't need a visible UI shell. Below code will help you run your script in headless mode

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--headless')
options.add_argument('--disable-gpu')  # Last I checked this was necessary.
driver = webdriver.Chrome("/usr/local/bin/chromedriver", chrome_options=options)
driver.get("https://google.com")
#code to extract the details
driver.quit()

3.Any other way - we can think of using Xserver - Not sure

Yosuva Arulanthu
  • 1,444
  • 4
  • 18
  • 32
  • The process is happening automated and in 5 minutes interval, so we cannot remote connect and start the execution. – Geo V Oct 10 '19 at 19:01
  • @GeoV you can setup a schedule task that will start it for you, and you can use say TeamViewer for seeing what is going on without interfering with the process itself. – Prix Oct 10 '19 at 19:04