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

Popular Categories





How to set cron job in server for python script

+3 votes
511 views
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__
    self.binary.launch_browser(self.profile)
  File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 68, in launch_browser
    self._wait_until_connectable()
  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))
display.start()

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

display.stop()

 

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))
display.start()

browser = webdriver.Firefox()
browser.get('http://edu.yoursfriends.com')
print browser.title
browser.quit()

display.stop()

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

Related Questions

+1 vote
2 answers 154 views
+4 votes
3 answers 889 views
+6 votes
3 answers 6,802 views
+5 votes
1 answer 55 views
0 votes
1 answer 357 views
+2 votes
1 answer 456 views
+4 votes
5 answers 1,987 views

Not a Member yet?

Ask to Folks Login

My Account
159 Folks are online
0 members and 159 guest online
Your feedback is highly appreciated