Reputation: 205
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
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
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)
Upvotes: 1
Views: 5019
Reputation: 1681
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
Upvotes: 0
Reputation: 11
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 Driver Download: https://chromedriver.chromium.org/downloads
Upvotes: 0
Reputation: 369
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
Upvotes: 0
Reputation: 14295
I had the same issue (with a newer "headless" version) and the solution was to run the Windows Scheduled Task as "Administrators" (with "s").
Upvotes: 0
Reputation: 15200
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)
Upvotes: 3