0

I have made a simple program that opens a new tab in my default browser when clicked the Open OpenSea Tab button, here:

import tkinter as tk 
import webbrowser


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

def open_chrome_profile():
    webbrowser.open_new_tab('https://opensea.io/asset/create') #open a new tab using user's default browser
   

#####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) #give some specifications
#####BUTTON ZONE END#######
root.mainloop()

GUI preview:

GUI

Result after clicking the "Open OpenSea Tab" button: OpenSea

So far so good, now, it happens that I need to make the program above interact with the OpenSea Tab, specifically to evaluate if the OpenSea page is asking the user for connecting a wallet or not, so I know I can use Selenium package for that, and I tried first to make this program open a window in my default browser using the following code:

import tkinter as tk 
#from tkinter import filedialog
#import webbrowser
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()

chrome_options.add_argument("--user-data-dir="+r"C:\Users\ResetStoreX\AppData\Local\BraveSoftware\Brave-Browser\User Data\Default") # change to profile path
chrome_options.add_argument('--profile-directory='+'Default')

driver = webdriver.Chrome(executable_path="C:\Program Files (x86)\BraveSoftware\Brave-Browser\Application\brave.exe", chrome_options=chrome_options) # change the executable_path too

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

def open_chrome_profile():
    driver.ExecuteScript("window.open('your URL', '_blank');") #open a new tab using user's default browser
   

#####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) #give some visual specifications for the button
#####BUTTON ZONE END#######
root.mainloop()

But it threw the following errors:

C:\Users\ResetStoreX\Pictures\Cryptobote\Cryptobote NFTs\Crypto Cangrejos\bulk masive\bulk-dozer.py:19: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
driver = webdriver.Chrome(executable_path="C:\Program Files (x86)\BraveSoftware\Brave-Browser\Application\brave.exe", chrome_options=chrome_options) # change the executable_path too C:\Users\ResetStoreX\Pictures\Cryptobote\Cryptobote NFTs\Crypto Cangrejos\bulk masive\bulk-dozer.py:19: DeprecationWarning: use options instead of chrome_options driver = webdriver.Chrome(executable_path="C:\Program Files (x86)\BraveSoftware\Brave-Browser\Application\brave.exe", chrome_options=chrome_options) # change the executable_path too Traceback (most recent call last):

File "C:\Users\ResetStoreX\miniconda3\envs\spyder-env\lib\site-packages\selenium\webdriver\common\service.py", line 71, in start self.process = subprocess.Popen(cmd, env=self.env,

File "C:\Users\ResetStoreX\miniconda3\envs\spyder-env\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in init super(SubprocessPopen, self).init(*args, **kwargs)

File "C:\Users\ResetStoreX\miniconda3\envs\spyder-env\lib\subprocess.py", line 951, in init self._execute_child(args, executable, preexec_fn, close_fds,

File "C:\Users\ResetStoreX\miniconda3\envs\spyder-env\lib\subprocess.py", line 1420, in _execute_child hp, ht, pid, tid = _winapi.CreateProcess(executable, args,

FileNotFoundError: [WinError 2] El sistema no puede encontrar el archivo especificado

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "C:\Users\ResetStoreX\Pictures\Cryptobote\Cryptobote NFTs\Crypto Cangrejos\bulk masive\bulk-dozer.py", line 19, in driver = webdriver.Chrome(executable_path="C:\Program Files (x86)\BraveSoftware\Brave-Browser\Application\brave.exe", chrome_options=chrome_options) # change the executable_path too

File "C:\Users\ResetStoreX\miniconda3\envs\spyder-env\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 70, in init super(WebDriver, self).init(DesiredCapabilities.CHROME['browserName'], "goog",

File "C:\Users\ResetStoreX\miniconda3\envs\spyder-env\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 90, in init self.service.start()

File "C:\Users\ResetStoreX\miniconda3\envs\spyder-env\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start raise WebDriverException(

WebDriverException: 'Applicatiorave.exe' executable needs to be in PATH. Please see https://chromedriver.chromium.org/home

I know I ended up breaking my program very badly, so I would like to know what did go wrong?

Or if there's a more simple way to interact with the OpenSea tab using the initial code, I'm all ears...

merv
  • 67,214
  • 13
  • 180
  • 245
NoahVerner
  • 937
  • 2
  • 9
  • 24

1 Answers1

0

Sorry for posting another answer, but this is what you should actually do.

You are calling ExecuteScript, but you should be calling execute_script.

I couldn't find any docs on either of them, but it seems that execute_script is what you should use.

With that, your code would look like:

import tkinter as tk 
#from tkinter import filedialog
#import webbrowser
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()

chrome_options.add_argument("--user-data-dir="+r"C:\Users\ResetStoreX\AppData\Local\BraveSoftware\Brave-Browser\User Data\Default") # change to profile path
chrome_options.add_argument('--profile-directory='+'Default')

driver = webdriver.Chrome(executable_path="C:\Program Files (x86)\BraveSoftware\Brave-Browser\Application\brave.exe", chrome_options=chrome_options) # change the executable_path too

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

def open_chrome_profile():
    driver.ExecuteScript("window.open('your URL', '_blank');") #open a new tab using user's default browser
   

#####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) #give some visual specifications for the button
#####BUTTON ZONE END#######
root.mainloop()
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • I got the following error ```WebDriverException: 'Applicatiorave.exe' executable needs to be in PATH. Please see https://chromedriver.chromium.org/home``` Any idea what's this file about? – NoahVerner Jan 14 '22 at 02:03
  • @NoahVerner Sorry this is late, internet issues, but when you downloaded the driver, where did you put it. Also, what OS are you on? (will help with path variables) – ThatBirdThatLearnedToCode Jan 15 '22 at 00:52
  • Don't worry, I already got my answer in another question: https://stackoverflow.com/questions/70706951/why-is-my-spyder-kernel-crashing-after-opening-a-chrome-browser-instance-with-my/70707263?noredirect=1#comment124998182_70707263 @ThatBirdThatLearnedToCode – NoahVerner Jan 15 '22 at 02:53
  • @NoahVerner Looking back, its probably for the best that you create an answer that shows what to do (just in case anyone else needs help here) – ThatBirdThatLearnedToCode Jan 29 '22 at 18:06