Metamask automation with Selenium webdriver
Asked Answered
Q

2

16

I'm trying to get to a Dapp that needs Metamask extension to access it. I added it through chrome extension. I know how to add the extension to the chrome instance in selenium but I don't know how to add a password etc..Could anyone download Metamask and give me an example of how I could pass credentials through selenium using it?

 ChromeOptions options = new ChromeOptions();
 options.addArguments("--start-maximized");
 options.addExtensions(newFile("//Applications//chrome//MetaMask_v3.13.8.crx"));                
 driver = new ChromeDriver(options);
Qua answered 31/1, 2018 at 2:19 Comment(1)
did you get solution for this problem?Kendall
R
2

Due to rather complex process of wallet info input in Metamask, it seems like the best way to get your test to work with Metamask extension is to start Chrome with defined profile directory use preconfigured Chrome profile:

# google-chrome -user-data-dir=/tmp/profile

then add Metamask extension and configure your wallet manually, and then add the correspondent argument to WebDriver options to use this profile instead of creating an empty one:

options.addArguments("user-data-dir=/tmp/profile");

Then, in test, you'll have to re-enter the Metamask's password and you'll all set.

Rohde answered 1/6, 2021 at 11:11 Comment(0)
P
0

Here is simple example how you can easily create different profiles and load them. Automating extension is not that hard you simple have to open it as page and interact with it like another page.

headless_options = Options()
headless_options.add_argument("--start-maximized");
headless_options.add_extension("extension_10_9_0_0.crx");
headless_options.add_argument("user-data-dir=C:/Users/V/Documents/STACKS OVERFLOW/Test")  # Save Profile
headless_options.add_argument("--profile-directory=test")  # Choose witch profile you would like to use
driver = webdriver.Chrome(options=headless_options)
driver.get(
    'chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/home.html#initialize/create-password')  # Go straight to creating Metamaks wallet

driver.switch_to.window(driver.window_handles[1])  # Switch to main tab

driver.find_element(By.ID, "create-password").send_keys("IlovePython")
driver.find_element(By.ID, "confirm-password").send_keys("IlovePython")
driver.find_element(By.CLASS_NAME, "first-time-flow__checkbox").click()

driver.find_element(By.XPATH, "//*[@id=\"app-content\"]/div/div[2]/div/div/div[2]/form/button").click()
Pinole answered 9/2, 2022 at 0:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.