I have small portion of a solution that I am having difficulty with.
I am using Selenium and chromedriver to drive an instance via remote debugging port.
In a nutshell this is what I am trying to do:
Launch a remote debugging chromedriver instance at the beginning of the script that does not occupy the terminal, and not close the instance when the script is terminated
I'd like to have it all in a single script, if possible. Currently, I have a separate script that I call from my main script.
What is the best practice for this type of scenario?
Current code:
(script to launch chromedriver)
`from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
Path to chromedriver executable
CHROMEDRIVER_PATH = 'c:\chromedriver\chromedriver.exe'
Set up Chrome options
chrome_options = Options()
chrome_options.add_argument(
"--remote-debugging-port=9222") # Specify remote debugging port
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument("--start-maximized")
Start a Selenium session and connect to the debugging instance
driver = webdriver.Chrome(service=Service(CHROMEDRIVER_PATH),
options=chrome_options)
input("Press 'enter' to kill Chromedriver.")`
From my main script, I am calling this (in its exe form)
`def start_remote_chromedriver():
subprocess.Popen(['/1.exe'],
creationflags=subprocess.CREATE_NEW_CONSOLE,
close_fds=True)
start_remote_chromedriver()
Do other stuff.`
For the life of me, I cannot figure out how to achieve the same thing from a single file. I am new to Python (and any coding beyond amateur level), so I don't know if this is possible, advisable, dumb, good, or none?
I am looking for any feedback. I don't know a single person in real life to talk to about this stuff. LOL Thanks in advance.