Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will my selenium script in execution stops if my computer goes on sleep mode/ hibernate mode ?in my absence? i

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?

like image 264
Harsh Nigam Avatar asked May 28 '15 09:05

Harsh Nigam


People also ask

Can you run Selenium in the background?

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.

How do I run Selenium in headless mode?

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.

Does Selenium work on Linux?

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.


2 Answers

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.

like image 194
SRM21 Avatar answered Sep 30 '22 11:09

SRM21


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")
like image 28
Matt Bart Avatar answered Sep 30 '22 11:09

Matt Bart