public void test() { int i = 1; bool notDone = true; while (notDone) { IWebElement bubble = PropertiesCollection.driver.FindElement(By.XPath("/html/body/div[2]/div[1]/div[1]/div[2]/div/div[2]/div/div[" + i + "]")); int num1 = Convert.ToInt32(PropertiesCollection.driver.FindElement(By.XPath("/html/body/div[2]/div[1]/div[1]/div[2]/div/div[2]/div/div[" + i + "]/div[1]")).Text); int num2 = Convert.ToInt32(PropertiesCollection.driver.FindElement(By.XPath("/html/body/div[2]/div[1]/div[1]/div[2]/div/div[2]/div/div[" + i + "]/div[2]")).Text); if (num1 > num2) { Swap.Click(); Thread.Sleep(250); Next.Click(); Thread.Sleep(250); i++; } else { Next.Click(); Thread.Sleep(250); i++; } Console.WriteLine(i); if (i == 9 && Done.Text.Equals("KEEP SORTING")) { i = 1; Thread.Sleep(150); } if (!(Done.Text.Equals("KEEP SORTING"))) { notDone = false; } } Done.Click(); Thread.Sleep(800); Assert.IsTrue(Completed.Text.Contains("Good job"), "Not Completed"); ClosePopUp.Click(); }