Python Using an existing google chrome profile with selenium chrome web driver

0 votes

I want to load my existing google chrome profile with all chrome extensions.

It is throwing some error. Below is the code also:

chrome_options = Options()

chrome_options.add_argument('user-data-dir= C:\Users\DMMaxim\AppData\Local\Google\Chrome\User Data')

capabilities = DesiredCapabilities.CHROME.copy()

chromedriver = r"C:\Users\DMMaxim\Desktop\chromedriver_win32\chromedriver.exe" 

driver = webdriver.Chrome(executable_path=chromedriver, chrome_options = chrome_options, desired_capabilities=capabilities)

Below is the error:

C:\Users\DMMaxim\Desktop>python ExportbacktestTradingview.py

  File "ExportbacktestTradingview.py", line 21

    chrome_options.add_argument('--user-data-dir=C:\Users\DMMaxim\AppData\Local\Google\Chrome\User Data')

                               ^

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 18-19: truncated \UXXXXXXXX escape

Below is my source code:

from selenium import webdriver

from selenium.webdriver import ActionChains

from selenium.webdriver.chrome.options import Options

from selenium.webdriver.common.keys import Keys

from selenium.webdriver.common.by import By

from selenium.webdriver.support.ui import WebDriverWait

from selenium.webdriver.support import expected_conditions as EC

from selenium.webdriver import DesiredCapabilities

from subprocess import Popen

from time import gmtime, strftime

from os import system

import subprocess

import pyperclip

import datetime

import time

import os

import sys

timer=0

chrome_options = Options()

chrome_options.add_argument('user-data-dir= C:\Users\DMMaxim\AppData\Local\Google\Chrome\User Data')

capabilities = DesiredCapabilities.CHROME.copy()

chromedriver = r"C:\Users\DMMaxim\Desktop\chromedriver_win32\chromedriver.exe" 

driver = webdriver.Chrome(executable_path=chromedriver, chrome_options = chrome_options, desired_capabilities=capabilities)

driver.get("https://www.tradingview.com/chart/gK6Rq0UH/")

driver.implicitly_wait(90)

driver.find_element_by_xpath("""//*[@id="footer-chart-panel"]/div[2]/span[4]""").click()

driver.implicitly_wait(90)

while True:

    driver.implicitly_wait(90)

    driver.find_element_by_xpath("""//*[@id="bottom-area"]/div[2]/div[1]/div[2]/ul/li[4]""").click()

    driver.implicitly_wait(90)

    timer=timer+1

    time.sleep(1)

    if timer > 250:

Jul 4, 2018 in Selenium by Martin
• 4,320 points
13,128 views

2 answers to this question.

0 votes
Check below:

chromedriver = r"C:\Users\DMMaxim\Desktop\chromedriver_win32\chromedriver.exe"
answered Jul 4, 2018 by Samarpit
• 5,910 points
0 votes

The problem is with the string

"C:\Users\Eric\Desktop\beeline.txt"

Here, \U starts an eight-character Unicode escape, such as '\U00014321`. In your code, the escape is followed by the character 's', which is invalid.

You either need to duplicate all backslashes, or prefix the string with r (to produce a raw string).

answered May 24, 2019 by shinio llahsra
Hi @Shinio. Can you please explain what you mean by "duplicate all backslashes"

Hi @John, I think what @Shinio meant to say by "duplicate all backslashes" is to add additional backslashes to the path string i.e. if the Path is: 

"C:\Users\Eric\Desktop\beeline.txt" 

then to avoid the escape character error use this: 

"C:\\Users\\Eric\\Desktop\\beeline.txt"

Related Questions In Selenium

0 votes
2 answers

Get text using selenium web driver in python

text = driver.find_element_by_class_name("current-text").getText(); ...READ MORE

answered Feb 4, 2019 in Selenium by anonymous
38,101 views
0 votes
1 answer
+1 vote
2 answers

Python with Selenium issue: “Chrome is being controlled by automated test software”

from selenium import webdriver chrome_options = webdriver.ChromeOptions() chrome_options.add_experimental_option("useAutomationExtension", False) chrome_options.add_experimental_option("excludeSwitches",["enable-automation"]) driver ...READ MORE

answered Apr 20, 2020 in Selenium by Manoj
15,897 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
13,674 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,143 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
7,221 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,874 views
+1 vote
1 answer
0 votes
3 answers

How to click the search button using Selenium web driver and Python

You can try with tag. #this code will ...READ MORE

answered Apr 10, 2019 in Selenium by Matin
16,244 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP