Python Selenium metamask automation error

189 views Asked by At

I'm trying to automate metamask (crypto wallet extension) login on a website and I get an error when trying to find the password input element. I have managed to kind of come up with a fix but I don't understand why it wouldn't work before. This post covers this error but in a different context: Runtime.callFunctionOn threw exception: Error: LavaMoat - property "Proxy" of globalThis is inaccessible under scuttling mode.

The non-working code:

window_handles = driver.window_handles
button_metamask = wait.until(EC.element_to_be_clickable((By.XPATH, '//button[(@data-testid="rk-wallet-option-metaMask")]')))


button_metamask.click()
time.sleep(5)
       
wait.until(EC.new_window_is_opened(window_handles))
    
main_window = driver.current_window_handle
driver.switch_to.window(driver.window_handles[-1])
#exception thrown here v
inp = wait.until(EC.presence_of_element_located((By.XPATH, '//input')))

Message: unknown error: Runtime.callFunctionOn threw exception: Error: LavaMoat - property "Proxy" of globalThis is inaccessible under scuttling mode. To learn more visit https://github.com/LavaMoat/LavaMoat/pull/360.

The working code:

window_handles = driver.window_handles
    button_metamask = wait.until(EC.element_to_be_clickable((By.XPATH, '//button[(@data-testid="rk-wallet-option-metaMask")]')))

#this opens metamask
button_metamask.click()

       
wait.until(EC.new_window_is_opened(window_handles))

time.sleep(5)
main_window = driver.current_window_handle
#switch to metamask window
driver.switch_to.window(driver.window_handles[-1])
inp = wait.until(EC.presence_of_element_located((By.XPATH, '//input')))

All I did was change the position of time.sleep(5). I don't necessarily need the time.sleep(5), it is just an example, but, instead, I need to wait for another element on the main window before switching to the metamask pop-up. Why would the position of a time.sleep() cause such an exception? I have also tried using another EC.number_of_windows_to_be(window_handles+1), but that didn't work.

0

There are 0 answers