Python Forum
Selenium: can't open a new window after clicking a button and I don't know why
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Selenium: can't open a new window after clicking a button and I don't know why
#1
Sad 
I have a simple python program that opens this page with chromedriver.exe, then it clicks on the wallet icon located at the top right corner of that page, for then clicking on the MetaMask wallet button, here:

    from selenium import webdriver
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.common.by import By
    from selenium.webdriver.chrome.options import Options
    from selenium.webdriver.chrome.service import Service

    opt.add_argument('--user-data-dir='+r'C:\Users\ResetStoreX\AppData\Local\Google\Chrome\User Data') #Add the user data path as an argument in selenium Options
    opt.add_argument("--profile-directory=Default") #Add the profile directory as an argument in selenium Options
    s = Service(r'C:\Users\ResetStoreX\AppData\Local\Programs\Python\Python39\Scripts\chromedriver.exe') #Use the chrome driver located at the corresponding path  

    driver = webdriver.Chrome(service=s, options=opt) #execute the chromedriver.exe with the previous conditions
    driver.implicitly_wait(10)
    driver.get('https://opensea.io/') #go to the opensea main page.

    initial_page = driver.current_window_handle  #make the previous page the current one
    WebDriverWait(driver, 3).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="__next"]/div/div[1]/nav/ul/div[2]/li/button'))) #wait for the wallet button to be enabled for clicking
    wallet_button = driver.find_element(By.XPATH, '//*[@id="__next"]/div/div[1]/nav/ul/div[2]/li/button')
    wallet_button.click() #click that wallet button
    #time.sleep(1)
    wallet_options = driver.find_elements(By.XPATH, "//*[@data-testid='WalletSidebar--body']//li")
    for i in wallet_options:
        if "MetaMask" in i.get_attribute('innerText'): #find the MetaMask wallet button
            i.click() #click the MetaMask wallet button
I noticed a weird problem when testing this program, it was that after clicking the MetaMask wallet button via automation, the expected Metamask Notification window was never displayed, and the current window kept loading that button eternally as shown below:

[Image: kwGuB.png]

However, if the user manually clicked the same MetaMask wallet button in the same chrome instance, the Metamask Notification window would immediately appear as expected, asking the user to log in for then connecting the wallet to that site, as shown below:

[Image: tXoVW.png]

I even checked if there was another hidden window handle after pressing the MetaMask wallet button (via automation) with this code, but there was nothing else:

    for handle in driver.window_handles:
                if handle != initial_page:
                    login_page = handle
                    driver.switch_to.window(login_page)
So, I'm confused, why does that button apparently only work when a user presses it but not when a program does? As always, I'd appreciate a lot if someone could explain what's happening and how could I fix this?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Open files in an existing window instead of new Kostov 2 298 Apr-13-2024, 07:22 AM
Last Post: Kostov
  Is there a way to call and focus any popup window outside of the main window app? Valjean 6 1,771 Oct-02-2023, 04:11 PM
Last Post: deanhystad
  how to open a popup window in tkinter with entry,label and button lunacy90 1 881 Sep-01-2023, 12:07 AM
Last Post: lunacy90
Bug tkinter.TclError: bad window path name "!button" V1ber 2 790 Aug-14-2023, 02:46 PM
Last Post: V1ber
  Open a new window does not work Nietzsche 4 1,087 Jun-14-2023, 08:52 AM
Last Post: Nietzsche
  Start print a text after open an async task via button Nietzsche 0 706 May-15-2023, 06:52 AM
Last Post: Nietzsche
  Pyspark Window: perform sum over a window with specific conditions Shena76 0 1,172 Jun-13-2022, 08:59 AM
Last Post: Shena76
  I can't open a link with Selenium in Python jao 0 1,403 Jan-30-2022, 04:21 AM
Last Post: jao
  Closing Threads and the chrome window it spawned from Tkinter close button law 0 1,706 Jan-08-2022, 12:13 PM
Last Post: law
  Clicking Every Page and Attachment on Website shoulddt 1 1,738 Jul-09-2021, 01:08 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020