My selenium driver wont open my chrome profile. Chrome drivers are same with my chrome version. It just opens clean browser.
Here is code:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
options = Options()
browser = webdriver.Chrome(executable_path="C:/Users/rektl/Desktop/csdd projekts/chromedriver.exe", chrome_options=options)
options.add_argument("user-data-dir=C:/Users/Rektl/AppData/Local/Google/Chrome/User Data/Profile 2")
browser.get("https://google.com")
Some error codes if that will help:
[8052:3876:0303/141810.953:ERROR:device_event_log_impl.cc(214)] [14:18:10.953] USB: usb_device_handle_win.cc:1049 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[8052:3876:0303/141810.965:ERROR:device_event_log_impl.cc(214)] [14:18:10.965] USB: usb_device_handle_win.cc:1049 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[8052:3988:0303/141810.995:ERROR:chrome_browser_main_extra_parts_metrics.cc(239)] END: GetDefaultBrowser()
CodePudding user response:
Try this: Copy profile path from chrome://version/
e.g. C:\Users\pcuser\AppData\Local\Google\Chrome\User Data\Default
opt = webdriver.ChromeOptions()
opt.binary_location = r'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe'
chromedriver_exe_location = os.path.join(os.getcwd(), 'chromedriver.exe')
profile_path = r'C:\\Users\\pcuser\\AppData\\Local\\Google\\Chrome\\User Data' # path minus last folder
opt.add_argument('--user-data-dir={}'.format(profile_path))
opt.add_argument('--profile-directory={}'.format('DEFAULT')) # last folder name
driver = webdriver.Chrome(chromedriver_exe_location, options=opt, service_args='')
CodePudding user response:
You defined the optins
but added the values there only after creating the web driver instance so this will have no effect.
You should put the line
options.add_argument("user-data-dir=C:/Users/Rektl/AppData/Local/Google/Chrome/User Data/Profile 2")
Before
browser = webdriver.Chrome(executable_path="C:/Users/rektl/Desktop/csdd projekts/chromedriver.exe", chrome_options=options)
Please try this:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
options = Options()
options.add_argument("user-data-dir=C:/Users/Rektl/AppData/Local/Google/Chrome/User Data/Profile 2")
browser = webdriver.Chrome(executable_path="C:/Users/rektl/Desktop/csdd projekts/chromedriver.exe", chrome_options=options)
browser.get("https://google.com")