Hey there! any question in your mind? Ask It Now!.

Popular Categories

How to set cron job in server for python script

+3 votes
asked in Programming by tester (1,550 points)

I have created a selenium script in python and set a cron in server to run that script like this :

30 9 * * * cd '/var/www/html/py/' ; /usr/local/bin/python2.7 test.py > /tmp/Check_bot5.log 2>&1

And getting this error on log file :

Traceback (most recent call last):
  File "Top10FeatureCheck.py", line 48, in <module>
    driver = webdriver.Firefox(firefoxProfile)
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 77, in __init__
    self.binary, timeout),
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/extension_connection.py", line 49, in __init__
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 68, in launch_browser
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 98, in _wait_until_connectable
    raise WebDriverException("The browser appears to have exited "
selenium.common.exceptions.WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.

Please help me to resolve this problem or give me some way to execute python script by crontab in server.


1 Answer

0 votes
answered by Himanshu Expert (5,940 points)
edited by Himanshu

I was facing the same problem , you just need to follow these steps to resolve this issue :


Step 1.  Run these command to install xvfb and pyvirtualdisplay.

    $ sudo apt-get install xvfb python-pip
    $ sudo pip install pyvirtualdisplay

For centOs :

    $ yum install xvfb python-pip
    $ pip install pyvirtualdisplay

What are doing here : we are providing display PyVirtualDisplay so that firefox driver can get a environment to run.


Step 2. Now you have to define display in you code like this :


display = Display(visible=0, size=(800, 600))

And at the end of the code you have to close the display like:



So let's have a example of a selenium script including these display command :

from pyvirtualdisplay import Display
from selenium import webdriver

display = Display(visible=0, size=(800, 600))

browser = webdriver.Firefox()
print browser.title


After following these 2 steps this problem was resolved for me , I hope it will help you, Enjoy!

Related Questions

+1 vote
2 answers 283 views
+4 votes
3 answers 1,068 views
+6 votes
3 answers 7,425 views
+5 votes
1 answer 130 views
+2 votes
1 answer 1,300 views
+4 votes
5 answers 4,285 views
+2 votes
3 answers 363 views

Not a Member yet?

Ask to Folks Login

My Account
345 Folks are online
2 members and 343 guest online
Your feedback is highly appreciated