1

I have up and running an Apache Server with Python 3.x installed already on it. Right now I am trying to run ON the server a little python program (let's say filename.py). But this python program uses the webdriver for Chrome from Selenium. Also it uses sleep from time (but I think this comes by default, so I figure it won't be a problem)

from selenium import webdriver

When I code this program for the first time on my computer, not only I had to write the line of code above but also to manually download the webdriver for Chrome and paste it on /usr/local/bin. Here is the link to the file in case you wonder: Webdriver for Chorme

Anyway, I do not know what the equivalences are to configure this on my server. Do you have any idea how to do it? Or any concepts I could learn related to installing packages on an Apache Server?

1 Answers1

1

Simple solution:

You don't need to install the driver in usr/local/bin. You can have the .exe anywhere and you can specify that with an executable path, see here for an example.

Solution for running on a server

If you have python installed on the server, ideally >3.4 which comes with pip as default. Then install ChromeDriver on a standalone server, follow the instructions here

Note that, Selenium always need an instance of a browser to control.

Luckily, there are browsers out there that aren't that heavy as the usual browsers you know. You don't have to open IE / Firefox / Chrome / Opera. You can use HtmlUnitDriver which controls HTMLUnit - a headless Java browser that does not have any UI. Or a PhantomJsDriver which drives PhantomJS - another headless browser running on WebKit.

Those headless browsers are much less memory-heavy, usually are faster (since they don't have to render anything), they don't require a graphical interface to be available for the computer they run at and are therefore easily usable server-side.

Sample code of headless setup

op = webdriver.ChromeOptions()
op.add_argument('headless')
driver = webdriver.Chrome(options=op)

It's also worth reading on running Selenium RC, see here on that.

AzyCrw4282
  • 7,222
  • 5
  • 19
  • 35
  • Thanks so much for taking the time. I will give this a try for sure. Sorry for the late reply, I have been stucked with work. Again, thanks! – nacarratala Apr 14 '20 at 01:02
  • No worries. Let me know the outcome. Thanks – AzyCrw4282 Apr 14 '20 at 01:02
  • The code you gave me worked! Now no google chrome instance is open when I run the program. However, when I try to run it through the server, the following error appears on the /var/log/apache2/error_filename.log: " ModuleNotFoundError: No module named 'selenium' " That is why I was concerned about installing selenium/webdriver correctly – nacarratala Apr 14 '20 at 13:37
  • Did you do `pip install selenium` to install the selenium module on the srerver – AzyCrw4282 Apr 14 '20 at 23:10
  • I did pip install selenium on my terminal, that is why it works when I run the program through my computer. But when I try to run it through the server, the "ModuleNotFoundError" appears – nacarratala Apr 14 '20 at 23:45
  • The idea [here](https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver) is that you need to install this on the server. In order to run on the server, the driver needs to be present there, so u must install it there. A side note, selenium tests aren't supposed to be tested on the server, but mainly on client-side (e.g. your pc). Your server is simply to be used to deploy production-ready code. – AzyCrw4282 Apr 17 '20 at 01:39