Skip to content

Instantly share code, notes, and snippets.

@bharathmuddada
Last active August 9, 2022 23:37
Show Gist options
  • Save bharathmuddada/d86d457ff03c1fc039abf31acdc1032f to your computer and use it in GitHub Desktop.
Save bharathmuddada/d86d457ff03c1fc039abf31acdc1032f to your computer and use it in GitHub Desktop.
C# Selenium Program for Explicit Wait
public class SeleniumExplicitWaitExample {
public static void Main(string[] args)
{
new DriverManager().SetUpDriver(new ChromeConfig());
var driver = new ChromeDriver();
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl("https://the-internet.herokuapp.com/dynamic_controls");
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
driver.FindElement(By.XPath("//button[contains(text(),'Remove')]")).Click();
wait.Until(e => e.FindElement(By.XPath("//button[contains(text(),'Add')]")));
driver.FindElement(By.XPath("//button[contains(text(),'Add')]")).Click();
driver.FindElement(By.XPath("//button[contains(text(),'Enable')]")).Click();
var disable_button = wait.Until(e => e.FindElement(By.XPath("//button[contains(text(),'Disable')]")));
Console.WriteLine(driver.FindElement(By.XPath("//p[@id='message']")).Text);
disable_button.Click();
driver.Quit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment