Will my selenium script in execution stops if my computer goes on sleep mode/ hibernate mode in my absence? if yes then what is the desired way to get rid of this?
Selenium Webdriver can run in the background, i.e. without opening a browser window, by running it in Headless mode. To do this you need to add the required capability to the set-up code for the driver.
ChromeOptions options = new ChromeOptions() options. addArgument("headless"); ChromeDriver driver = new ChromeDriver(options); In the above code, the browser is instructed to run in the headless mode using the addArgument() method of the ChromeOptions class provided by the Selenium WebDriver.
So, Selenium can do web automation, web scrapping, browser tests, etc. using the Chrome web browser in Linux servers where you don't have any graphical desktop environment installed. In this article, I am going to show you how to run Selenium with the Chrome web browser in headless mode.
First, Sleep or Hibernate will disconnect your internet services.
Second, Hibernate also discontinues or stops many processes.
In Sleep mode, your display is turned off by default.
So Selenium Webdriver will not found any screen to run the script.
Solution :
(1) Remove/Increase display turn off time from settings (Never turn off).
(2) Increase Sleep or Hibernate time also.
(3) If you want to run script from the locked system,you can run it with above solutions.
Note : Never run Selenium scripts in Sleep or Hibernate mode. You can lock your System. It will not discontinue execution of your scripts.
Thanks.
While this is an older question I thought I would answer this question as it may help someone else out. I have found that a selenium script can continue to run even in sleep mode (at least on Linux/Ubuntu). If you put the browser in headless mode when setting up the driver, it will continue even in sleep mode.
Here is a blog post discussing headless mode.
And here is a snippet that can be used if using Python and Firefox on Linux (should work on other OSes as well):
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.firefox.options import Options
options = Options()
options.add_argument("--headless")
browser = webdriver.Firefox(options=options)
browser.get("your_favorite_url_website_here")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With