Run a scheduled task with ChromeDriver

4.6k views Asked by At

I have made a script based on Selenium and Chromedriver. Basically a program that login into a site. Writes a comment (From a txt file from computer) and then closes the program and no it is not a spam script but a script I have made just to begin with python and selenium.

The program itself works very well if I start it manually. Then there is no issue and chromedriver is headless since I don't need to see the whole process chrome_options.add_argument("--headless")

Then I saw a post from here Scheduling a Python Script

and I did follow it The setup

but the issue im having is that everytime it is the time and the program starts. It comes up the script and then a fast error which I managed to print

The Error

Which I can see there is a issue with the Chromedriver. The thing is now. How can I make this script to work through schedule tasks with Chromedriver running on the background. I might have done the setup wrong but the program works manually so I guess there might be a issue with Windows schedule tasks?

Basically I just want the script to run on the background every xx:xx time.

Please feel free to comment if needed something more information.

    chrome_options = Options()
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument('--disable-notifications')
chrome_options.add_argument("--headless")
chrome_options.add_argument("--user-agent=Mozilla/5.0 (Linux; Android 6.0; HTC One M9 Build/MRA58K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.98 Mobile Safari/537.36")
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.implicitly_wait(5)
5

There are 5 answers

10
Isma On BEST ANSWER

The driver you are using is too old and does not recognize ChromeHeadless, you need to use version 2.29 or newer:

Selenium ChromeDriver does not recognize newly compiled Headless Chromium (Python)

0
TJacken On

I had this problem and almost give up from task scheduler and started to write windows service which would run my web scraping application. If you got exception chrome unreachable or chrome didn't get response from HTTP server...

This make my application work even through task scheduler.

Task Scheduler -> Go on task -> Properties -> Conditions > Under Network -> Check Network Start only if the following network connection is available -> Select "Any connection".

Go this from this post windows-10-task-scheduler-not-running

0
Cristian Galindo On

When using selenium with Chrome, you have to make sure that your selenium version is compatible with the chrome version you have installed. If you get the app to work and then update your chrome you might get an unrecognized version error.

If you have chrome v 102.0 like me, you need to get the latest selenium chrome driver that is the same version as your browser.

See Example Below:

Chrome version

Chrome Driver Download: https://chromedriver.chromium.org/downloads Chrome driver download

0
Marc On

I had the same issue (with a newer "headless" version) and the solution was to run the Windows Scheduled Task as "Administrators" (with "s").

0
HO LI Pin On

To prevent "outdated Chrome driver" error reoccur, basically you need to make sure your Chrome driver is up to date with the browser version (n-1) installed on your local PC . This process can be handled automatically using something call as "DriverManager"

In my case, I use this .NET web driver manager.Below is sample .NET code how to make latest Chrome driver automatically downloaded

    var StrDriverPtah = new DriverManager().SetUpDriver(new ChromeConfig(), "Latest", Architecture.X64);
    StrDriverPtah = StrDriverPtah.Replace("chromedriver.exe", "");
    IWebDriver driver = new ChromeDriver(StrDriverPtah, options, TimeSpan.FromSeconds(120)); 

For task scheduler setting , as long as you configured something as below, it shall work enter image description here