'How to transfer cookies from default browser to selenium webdriver?
out there. Right now I have the problem that I want some logins from my cookies to my selenium chrome browser.
I have done some tests, with no luck.
That is why I am asking here. Anyone know how to transfer cookies, from my default browser to my selenium webdriver browser?
My code looks like this:
import time
from selenium import webdriver
import getpass
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\\Default")
driver = webdriver.Chrome(executable_path=r'C:\Users\rober\Desktop\Bot\chromedriver.exe', chrome_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()
If anyone has an idea or a suggestion on how I do it then you are more than welcome to write.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
