I am trying to navigate to the active chrome tab using Selenium and Python code. However, when I run my code, it opens a new window with a new profile, not the profile that I have specified. I have tried many things to solve this issue, but I do not know what the problem is.
Here is my code:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
chrome_options = Options()
chrome_options.add_argument('--remote-debugging-port=9222')
#chrome_options.add_argument('--user-data-dir=C:\\Users\\loai\\AppData\\Local\\Google\\Chrome\\User Data')
#chrome_options.add_argument('--profile-directory=Profile 1')
driver = webdriver.Chrome(executable_path="C:\\path\\to\\chromedriver.exe", options=chrome_options)
driver.get("https://nft.bueno.art/NS1PNAih8UHV6y1XviWJU/art/kZK_iEBrl-kK8NY_UznyI/preview")
# Wait for the element to be present
wait = WebDriverWait(driver, 10)
element = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, ".virtuoso-grid-item")))
# Now you can execute your script
driver.execute_script("arguments[0].click();", element)
I have specified the profile path 'C:/Users/loai/AppData/Local/Google/Chrome/User Data/Profile 1', but it still creates a new profile and continues with it. I want to run my code with the already active tab that has the specified URL that I have mentioned in the browser.get line.
Does anyone have a suggestion on how to fix this issue or has had a similar issue in the past?
My chrome browser version is Version 109.0.5414.75 (Official Build) (64-bit).
I am trying to navigate to the active chrome tab using Selenium and Python code. However, when I run my code, it opens a new window with a new profile, not the profile that I have specified.