I'm using selenium to loop through my mailbox, click each mail and check if there is a specific button present. If there is, click it, if not keep looping.
The program works fine until there is a mail with no button, I receive the following error
error:
No such element found
My code:
    void LookForButtonInMail()
    {
        //Open browser and navigate to outlook mail in browser
        MailDriver = new ChromeDriver();
        MailDriver.Navigate().GoToUrl("https://outlook.office365.com/");
        //Create list of mails
        List<IWebElement> CustomerMailList = MailDriver.FindElements(By.ClassName("_1Dr0riVoOGchgeP7D9S09l")).ToList();
        //Loop through list of mails
        for (int i = 0; i < CustomerMailList.Count; i++)
        {
            //Click next mail in list
            CustomerMailList[i].Click();
            System.Threading.Thread.Sleep(2000);
            //Check if there is a button and click it, if not, next loop
            bool ButtonPresent = MailDriver.FindElement(By.XPath("Xpath")).Displayed;
            if (ButtonPresent = true)
            {
                IWebElement OpenButton = MailDriver.FindElement(By.XPath("Xpath"));
                OpenButton.Click();
            }
            else
            {
                Console.WriteLine("No button in this mail");
            }
            System.Threading.Thread.Sleep(2000);
        }
    }
I receive the error at line : bool ButtonPresent = MailDriver.FindElement(By.XPath("Xpath")).Displayed;
I'm using a console application in c# and dot.net
