0

I'm trying to open a website in my own browser, but I can not make it to work.

The code:

import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select

options = webdriver.ChromeOptions() 
options.add_argument("user-data-dir=C:\\\\Users\\rober\\AppData\\Local\\Google\\Chrome\\User Data")
driver = webdriver.Chrome(executable_path=r'C:\Users\rober\\Desktop\\Bot\chromedriver.exe', options=options)

driver.get("https://www.zalando.dk/jordan-air-jordan-1-mid-sneakers-high-joc12n001-a18.html")

buyButton = False

while buyButton is False:

    try:
        
        addToCartBtn = addButton = driver.find_element_by_xpath('/html/body/div[4]/div/div[2]/div/div/div[2]/div[1]/x-wrapper-re-1-6/div/div[4]/button')

        print("Varen er udsolgt")

        time.sleep(1)
        driver.refresh()

    except:
        addToCartBtn = addButton = driver.find_element_by_xpath('//*[@id="picker-trigger"]')

        print("Varen er på Lager")
        buyButton = True

while buyButton is True:
    time.sleep(1)
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.uc-btn#uc-btn-accept-banner"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Vælg størrelse']"))).click()
    driver.execute_script("return arguments[0].scrollIntoView(true);", WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//label[starts-with(@for, 'size-picker')]//span[text()='51.5']"))))
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//label[starts-with(@for, 'size-picker')]//span[text()='51.5']"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Læg i indkøbskurv']"))).click()
    WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'a[title="Indkøbskurv"]'))).click()
    WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".z-coast-base__totals-tile .z-1-button__content"))).click()
    WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'a[title="Registrér dig"]'))).click()

What error I'm getting:

selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir

What I have tried:

driver = webdriver.Chrome(executable_path=r'C:\Users\rober\\OneDrive\Skrivebord\\Bot\chromedriver.exe', options=options)

AND

driver = webdriver.Chrome(executable_path="C:\\Users\\rober\\OneDrive\\Skrivebord\\Bot\\chromedriver.exe", options=options)

But neither worked

So now I ask for help. If there are any wise heads out there who will help, I would be grateful

  • Does this answer your question? [InvalidArgumentException: Message: invalid argument: user data directory is already in use error using --user-data-dir to start Chrome using Selenium](https://stackoverflow.com/questions/59987080/invalidargumentexception-message-invalid-argument-user-data-directory-is-alre) – Bialomazur Feb 21 '22 at 15:20
  • You need to close down your browser first. You can't use devmode on a non-devmode launch of the browser. You can attach to an existing devmode session though. – pcalkins Feb 21 '22 at 19:54
  • Hey, Thanks for the comments I have tried it out but it was not working for me. @Bialomazur – Robert Tacchini Feb 22 '22 at 13:25
  • @pcalkins Thanks for the answer but it was not helpful because I couldn't get it to work. But Thanks for trying to help. – Robert Tacchini Feb 22 '22 at 13:27

0 Answers0