1

After the very exhaustive research of today, I managed to understand and make a simple program that will use the selenium module to open a chrome window with my user data and default profile, here:

import tkinter as tk 
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service

root = tk.Tk()
root.geometry('500x400') #resolution
root.title("Bulkdozer") #Name of this program
root.attributes('-topmost', True) #keep the program's window top-most

opt = Options() #selenium options
opt.add_argument("--user-data-dir="+r"C:\Users\ResetStoreX\AppData\Local\Google\Chrome\User Data\Default") #PATH profile
opt.add_argument('--profile-directory=Default') #Profile to use
s = Service('C:\Program Files\Google\Chrome\Application\chrome.exe')

def open_chrome_profile():
    driver = webdriver.Chrome(service=s, options=opt) 
    driver.get('https://opensea.io/asset/create')
    
#####BUTTON ZONE#######
open_browser = tk.Button(root, width=20,  text="Open OpenSea Tab", command=open_chrome_profile) #executes the function when clicked
open_browser.grid(row=22, column=1)
#####BUTTON ZONE END#######
root.mainloop()

The problem is that it is not working as expected at all:

First, after clicking the Open OpenSea Tab button, the program DOES open a chrome window with my user data and default profile, but it doesn't go to the link provided ('https://opensea.io/asset/create').

And second, it also crashes the GUI without throwing any errors, and even worse, it crashes the Spyder Kernel too!

problem

I'm very confused, to me it doesn't seem I have done any illegal stuff here, but I would appreciate a lot if someone could explain me how should I patch this issue?

I managed to build the code above following the recommendations from this other question, but I never expected ending up with a weird problem like this one in the end...

NoahVerner
  • 937
  • 2
  • 9
  • 24

1 Answers1

1

You need to take care of a couple of things here:

  • You need to remove Default from the profile PATH. So effectively your line of code will be:

    opt.add_argument("--user-data-dir=r'C:\Users\ResetStoreX\AppData\Local\Google\Chrome\User Data') #PATH profile
    

You can find a couple of relevant detailed discussions in:

  • You need to pass the absolute path of the ChromeDriver within Service() as follows:

    s = Service('C:\path\to\chromedriver.exe')
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    Thank you based god, these 2 things definitely patched the issue! If you don't mind, I have still a minor question left, which is, if I'm planning to build an executable file with this program, will that executable file include the ```chromedriver.exe``` from my machine and use it correctly in another PC after that user double-clicks the executable file? – NoahVerner Jan 14 '22 at 07:37
  • 1
    @NoahVerner Feel free to raise a new question with all the details and incase of emergency you may like to discuss in the [Selenium](https://chat.stackoverflow.com/rooms/223360/selenium) room. – undetected Selenium Jan 14 '22 at 07:43
  • 1
    Will do for sure! Again, thanks for your help @undetected Selenium – NoahVerner Jan 14 '22 at 10:00