0

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)
ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152
Thrillofit123
  • 195
  • 1
  • 2
  • 12

5 Answers5

2

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)

Isma
  • 14,604
  • 5
  • 37
  • 51
  • Im pretty sure I have downloaded the latest version of Chromedriver which I believe is 2.31. But I think the Schedule Tasks do not recognize it for some reason. Do I need to enter the Chromedriver into a special folder maybe to make the Tasks to recnogize it? – Thrillofit123 Aug 29 '17 at 09:36
  • Just add it to the windows PATH variable. In the screenshot of your answer it says chromedriver=2.25 so it seems you are using the incompatible version so maybe you have several versions installed and the PATH points to the wrong one. – Isma Aug 29 '17 at 09:39
  • I think the issue what is happening is that, Everytime I run the program manually. The chromedriver opens up and then does the script but when I do the Schedule tasks. It does not open the chromedriver which casusing it to close I believe. That mean that chromedriver is taking somewhere a older version instead of the new version I downloaded and it is only a exe file. – Thrillofit123 Aug 29 '17 at 09:46
  • Try this: os.environ["webdriver.chrome.driver"] = "path to your latest driver" add it before driver = webdriver.Chrome – Isma Aug 29 '17 at 09:50
  • I did that and it still takes me to the 2.25 version. That is very strange... And my version i located it to is 2.31.488763. but when I run through tasks it tells me 2.25. – Thrillofit123 Aug 29 '17 at 10:01
  • Did you check the Windows PATH? Also, make sure you are using the right version of Python if you have several installed e.g. 32, 64 bits – Isma Aug 29 '17 at 10:03
  • C:\WINDOWS\system32;C:\WINDOWS;C:\Users\Barry-PC\Desktop\fb\chromedriver.exe;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Git\cmd;C:\Program Files\nodejs\; Im pretty sure it is in the Path. – Thrillofit123 Aug 29 '17 at 10:04
  • Oh, I think im running on a 32x python on a 64x Windows but I mean, Is that still the issue? or casuing it? – Thrillofit123 Aug 29 '17 at 10:05
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/153115/discussion-between-isma-c-and-thrillofit123). – Isma Aug 29 '17 at 10:06
  • 1
    I can comment. The issue was that it took a chromedriver hidden from C:/Windows instead of the direction I picked. Strange but worked after updating the Chromedriver. – Thrillofit123 Aug 29 '17 at 10:16
0

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

Marc
  • 13,011
  • 11
  • 78
  • 98
0

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

TJacken
  • 354
  • 3
  • 12
0

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

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

HO LI Pin
  • 1,441
  • 13
  • 13