pythonselenium-webdrivercomputer-forensics

Python Selenium dummy website generation error after specifying profile


Im Working on a research project in Digital Browser forensics and I'm trying to generate a bunch of dummy data using selenium. Got my script working however I want it to run on my default profile. I have it opening the window and using my profile however I get this error message:

My sourcecode is below

Traceback (most recent call last):
  File "C:\Users\root\Desktop\webdata.py", line 16, in <module>
    "Chrome": webdriver.Chrome(options=chrome_options),
  File "C:\Users\root\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 45, in __init__
    super().__init__(
  File "C:\Users\root\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 56, in __init__
    super().__init__(
  File "C:\Users\root\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 205, in __init__
    self.start_session(capabilities)
  File "C:\Users\root\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 289, in start_session
    response = self.execute(Command.NEW_SESSION, caps)["value"]
  File "C:\Users\root\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 344, in execute
    self.error_handler.check_response(response)
  File "C:\Users\root\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 229, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited normally.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location C:\Users\root\AppData\Local\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Stacktrace:
    GetHandleVerifier [0x00007FF65E8952A2+57122]
    (No symbol) [0x00007FF65E80EA92]
    (No symbol) [0x00007FF65E6DE3AB]
    (No symbol) [0x00007FF65E706B1F]
    (No symbol) [0x00007FF65E702FE1]
    (No symbol) [0x00007FF65E73EA4F]
    (No symbol) [0x00007FF65E73E5B0]
    (No symbol) [0x00007FF65E736DB3]
    (No symbol) [0x00007FF65E70D2B1]
    (No symbol) [0x00007FF65E70E494]
    GetHandleVerifier [0x00007FF65EB3EF82+2849794]
    GetHandleVerifier [0x00007FF65EB91D24+3189156]
    GetHandleVerifier [0x00007FF65EB8ACAF+3160367]
    GetHandleVerifier [0x00007FF65E926D06+653702]
    (No symbol) [0x00007FF65E81A208]
    (No symbol) [0x00007FF65E8162C4]
    (No symbol) [0x00007FF65E8163F6]
    (No symbol) [0x00007FF65E8067A3]
    BaseThreadInitThunk [0x00007FFDC2CD7344+20]
    RtlUserThreadStart [0x00007FFDC2FC26B1+33]

Below is my sourcecode some help would be really appreciate here at my wits end!! Cheers all

import random
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options

# List of websites to visit
websites = ["https://www.example.com/", "http://birds.example.com/?bird=airplane&behavior=birth", "https://www.example.com/", "https://www.example.com/", "http://www.example.net/box"]
# Define the web browsers and their respective drivers
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument(r"user-data-dir=C:\Users\root\AppData\Local\Google\Chrome\User Data")

#chrome_options.add_argument('--user-data-dir='r'C:\Users\root\AppData\Local\Google\Chrome\User Data')
browsers = {

    "Chrome": webdriver.Chrome(options=chrome_options),
    #"Firefox": webdriver.Firefox(),
    #"Brave": webdriver.Chrome(executable_path="/path/to/brave/driver"),
    # "Edge": webdriver.Edge(executable_path="/path/to/edge/driver")
}

# Number of random visits
num_visits = 5

# Function to simulate page visits
def simulate_web_traffic(browser_name):
    browser = browsers[browser_name]
    browser.get(random.choice(websites))
    
    try:
        cookie_button = browser.find_element(By.XPATH, "//span[contains(text(),'Accept cookies;')]")  # Modify with actual element ID
        cookie_button.click()
    except Exception as e:
        pass

    time.sleep(random.uniform(3, 8))  # Simulate user interaction time

# Simulate web traffic for each browser
for browser_name in browsers.keys():
    print(f"Simulating web traffic for {browser_name}:")
    for _ in range(num_visits):
        simulate_web_traffic(browser_name)
    browsers[browser_name].quit()

Tried specifying the profile path which I have now got working however I cant get past the error message


Solution

  • Specify the profile name like below. If you want the default profile, it should be ..\User Data\Default. If the profile name is Profile 1, then it should be ..\User Data\Profile 1

    chrome_options.add_argument(r"user-data-dir=C:\Users\root\AppData\Local\Google\Chrome\User Data\Profile 1")