DEV Community

Leonardo Teixeira Menezes
Leonardo Teixeira Menezes

Posted on

Automated Dapps Scrapping with Metamask and C#

Hey everyone!
This article is a follow up on my last article about Daaps Scrapping, if you have not read it yet I suggest heading to:

Thank you all for the great feedback you provided in the last article, it's great to see people building their automations and sharing their own challenges.

One of my followers requested an example of how Metamask automation would look like in C#, so a built an automation for the same 'Import Wallet' flow:

static void Main(string[] args)
        ChromeOptions options = new ChromeOptions();
        IWebDriver driver = new ChromeDriver(CHROME_PATH, options);

        // Navigate to Metamask extension page

        // Enter Metamask import wallet flow
        driver.FindElement(By.XPath("//button[text()=\"Get Started\"]")).Click();
        driver.FindElement(By.XPath("//button[text()=\"Import wallet\"]")).Click();
        driver.FindElement(By.XPath("//button[text()=\"No Thanks\"]")).Click();

        // Send recovery phrase, password to import the wallet
        IList<IWebElement> inputFields = driver.FindElements(By.XPath("//input")).ToList();

        driver.FindElement(By.XPath("//button[text()=\"All Done\"]")).Click();

        // Close Metamask 'What's new' popup
Enter fullscreen mode Exit fullscreen mode

The concepts used here are the same as the previous article, we load Metamask extension to our ChromeDriver, navigate to its extension page and then automate the import flow as we would with any webpage.

It's good to note that the XPaths and CSS selectors used here might differ based on your Metamask extension version, so if you have issues in any of these steps jump over to your local ChromeDriver window and debug which selector broke the automation.

Let me know in the comments for which Dapp you are building your automation for and which challenges you're facing, I will make sure to address them in the next article!

Discussion (0)