Skip to content

Instantly share code, notes, and snippets.

@shivahari
Created May 9, 2024 09:38
Show Gist options
  • Save shivahari/f379fbe48681d78a65e3197ffdbf97e2 to your computer and use it in GitHub Desktop.
Save shivahari/f379fbe48681d78a65e3197ffdbf97e2 to your computer and use it in GitHub Desktop.
from selenium import webdriver
# Set Chrome Options
options = webdriver.ChromeOptions()
options.add_argument("–disable-notifications")
options.add_argument("–no-sandbox")
options.add_argument("–disable-dev-shm-usage")
options.add_argument("–enable-logging")
options.add_argument("–disable-blink-features=AutomationControlled")
options.add_experimental_option("detach", True)
# Instantiate Webdriver
driver = webdriver.Chrome(options=options)
# Get the session ID & CMD exec URL
session_id = driver.session_id
cmd_exec_url = driver.command_executor._url
print(f"The session id is {session_id} & the cmd exec url is {cmd_exec_url}")
# Reuse old session
driver = webdriver.Remote(command_executor=cmd_exec_url, options=options)
driver.session_id = session_id
print(f"The driver name is {driver.name} for reused session id {driver.session_id}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment