Skip to content

Instantly share code, notes, and snippets.

@bharathmuddada
Created August 9, 2022 23:39
Show Gist options
  • Save bharathmuddada/0c76679f0c8855a587553d78369c6131 to your computer and use it in GitHub Desktop.
Save bharathmuddada/0c76679f0c8855a587553d78369c6131 to your computer and use it in GitHub Desktop.
C# Selenium Fluent Wait Example
public class SeleniumFluentWait {
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))
{
PollingInterval = TimeSpan.FromSeconds(1),
};
driver.FindElement(By.XPath("//button[contains(text(),'Remove')]")).Click();
wait.Until(e => e.FindElement(By.XPath("//button[contains(text(),'Add')]")));
Console.WriteLine(driver.FindElement(By.XPath("//p[@id='message']")).Text);
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')]")));
disable_button.Click();
driver.Quit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment