我有从SH文件运行的Selenium脚本。 当我从控制台运行sh文件时,它工作得非常好, 但是从Cron作业运行的同一文件失败。Selenium脚本从控制台工作,不工作在CRON - Geckodriver错误
SH文件:
#!/bin/sh
export DISPLAY=:10
cd /home/user
python3 selenium.py > /home/user/selenium.log 2>&1
错误,我越来越众所周知:
Traceback (most recent call last): File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 74, in start stdout=self.log_file, stderr=self.log_file) File "/usr/lib/python3.5/subprocess.py", line 947, in init restore_signals, start_new_session) File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child raise child_exception_type(errno_num, err_msg) FileNotFoundError: [Errno 2] No such file or directory: 'geckodriver'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "so_login.py", line 12, in setUp self.driver = webdriver.Firefox() File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/webdriver.py", line 142, in init self.service.start() File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 81, in start os.path.basename(self.path), self.start_error_message) selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
我在控制台这个错误太多,但我通过安装geckodriver并将其移动到/解决它usr/local/bin,它在控制台上工作正常,但为什么它不能从CRON上运行?
如果你需要一个X -Windows/GUI session然后它不会与crontab一起工作,因为crontab不知道将哪个X-Windows会话与自己关联。 –
如何让它工作?我使用它像这里描述的无头像https://medium.com/@griggheo/running-selenium-webdriver-tests-using-firefox-headless-mode-on-ubuntu-d32500bb6af2 –
Cron假定不显示,所以没有帧缓冲区。因此我无法看到它与Cron合作。你有没有和詹金斯一起调度计划? –