'how to swicth to a metamask pop up in chrome with a python selenium script

i am on rarible.com minting a nft with metamask

i go threw the hole process then in the chrome browser a metamask pop up appears to click confirm the transaction, then a second to confirm agaian, it all used to runs smothly but now i can not seem to switch to the metamask mask pop up that appears in chrome

the way it works on rarible.com is you

  1. fill details and click create button (this works fine)
  2. a modal box appears overlaying the page and goes there the procees of upload to ipfs, then confirm metamask in step (3)
  3. metamask pop up appears (i can not focus to this to click the button needed)
  4. second metamask pop up appears (same as above)

this is my code that did before switch to the metamask pop up in chrome, but now i its not workin

is there a easier why to detect the window handles and define the metamask one easier, so i can click the elements i need in it??

    main_page = driver.current_window_handle
    while True:
        try:
            time.sleep(10) ###adjust this depending on your uplaod speed
            for handle in driver.window_handles:
                if handle != main_page:
                    login_page = handle
            driver.switch_to.window(login_page)
            css_and_click("button[class='button btn--rounded btn-primary btn--large']")
            driver.switch_to.window(main_page)
            break
        except Exception as wtf:
            #print(wtf)
            print("----- Waiting for metamask sign window -----")
            continue

heres a link to the full code i am using https://github.com/cloudmaking/Auto_Chrome_2/blob/main/Sample_Presets/rarible_metamask_v4.py



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source