简体   繁体   中英

How to keep browser session alive for 10 min on heroku using selenium?

This is the code I used. I need the browser session to stay alive for 10 min.

chrome_options = webdriver.ChromeOptions()
chrome_options.binary_location = os.environ.get("GOOGLE_CHROME_BIN")
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument("--no-sandbox")
s = Service(executable_path=os.environ.get("CHROMEDRIVER_PATH"))
driver = webdriver.Chrome(service=s, options=chrome_options)
driver.get(URL)
button = driver.find_element(by=By.XPATH,value='XPATH')
button.click()
time.sleep(600)
driver.quit()

These are the errors I am getting in logs

2022-05-16T15:06:47.277256+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2022-05-16T15:06:48.362371+00:00 heroku[web.1]: Process exited with status 137
2022-05-16T15:06:47.953605+00:00 heroku[web.1]: Stopping process with SIGKILL
2022-05-16T15:06:48.465543+00:00 heroku[web.1]: State changed from starting to crashed

I have found this useful maybe it will be helpful for you.

selenium keep the browser open

options = webdriver.ChromeOptions()
options.add_experimental_option("detach", True)
driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')

how to keep a webdriver tab open

options = webdriver.ChromeOptions()
options.add_experimental_option("detach", True)
driver = webdriver.Chrome(options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')

selenium open inspect

from selenium import webdriver

options = webdriver.ChromeOptions() 
options.add_argument("start-maximized")
options.add_argument("--auto-open-devtools-for-tabs")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
driver.get("https://selenium.dev/documentation/en/")
print(driver.title)

Source: https://www.codegrepper.com/code-examples/python/selenium+keep+browser+open

thank you have a nice day.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM