{"id":22173679,"url":"https://github.com/stefruseva88/web-driver-waits","last_synced_at":"2026-01-31T23:40:55.872Z","repository":{"id":255870950,"uuid":"852108582","full_name":"StefRuseva88/web-driver-waits","owner":"StefRuseva88","description":"Different types of waits in Selenium","archived":false,"fork":false,"pushed_at":"2024-11-28T17:15:30.000Z","size":172,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-14T08:42:19.102Z","etag":null,"topics":["nunit-tests","selenium-csharp","selenium-waits","selenium-webdriver"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/StefRuseva88.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-09-04T08:36:49.000Z","updated_at":"2025-02-06T17:34:58.000Z","dependencies_parsed_at":"2025-06-14T08:38:20.287Z","dependency_job_id":"384c3855-12eb-42ed-a746-3402402cd87a","html_url":"https://github.com/StefRuseva88/web-driver-waits","commit_stats":null,"previous_names":["stefruseva88/web-driver-waits"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/StefRuseva88/web-driver-waits","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StefRuseva88%2Fweb-driver-waits","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StefRuseva88%2Fweb-driver-waits/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StefRuseva88%2Fweb-driver-waits/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StefRuseva88%2Fweb-driver-waits/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/StefRuseva88","download_url":"https://codeload.github.com/StefRuseva88/web-driver-waits/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StefRuseva88%2Fweb-driver-waits/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28960611,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-31T23:03:11.038Z","status":"ssl_error","status_checked_at":"2026-01-31T22:56:44.691Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nunit-tests","selenium-csharp","selenium-waits","selenium-webdriver"],"created_at":"2024-12-02T07:34:41.793Z","updated_at":"2026-01-31T23:40:55.854Z","avatar_url":"https://github.com/StefRuseva88.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Selenium Waits and Web Interactions\n[![C#](https://img.shields.io/badge/Made%20with-C%23-239120.svg)](https://learn.microsoft.com/en-us/dotnet/csharp/)\n[![Google Chrome](https://img.shields.io/badge/tested%20on-Google%20Chrome-4285F4.svg)](https://www.google.com/chrome/)\n[![NUnit](https://img.shields.io/badge/tested%20with-NUnit-22B2B0.svg)](https://nunit.org/)\n[![Selenium](https://img.shields.io/badge/tested%20with-Selenium-43B02A.svg)](https://www.selenium.dev/)\n### This is a test project for Front-End Test Automation July 2024 Course @ SoftUni\n---\n\nThis repository provides detailed information and examples on how to handle waits in Selenium WebDriver, including the consequences of not using waits and the various types of waits you can use.\n\n## Table of Contents\n\n- [Introduction](#introduction)\n- [Consequences of Not Using Waits](#consequences-of-not-using-waits)\n- [Types of Waits in Selenium](#types-of-waits-in-selenium)\n  - [Thread.sleep](#threadsleeptime)\n  - [Implicit Wait](#implicit-wait)\n  - [Explicit Wait](#explicit-wait)\n  - [Fluent Wait](#fluent-wait)\n- [Working with Alerts](#working-with-alerts)\n  - [Handling Alerts](#handling-alerts)\n  - [Types of Alerts](#types-of-alerts)\n- [Working with iFrames](#working-with-iframes)\n  - [Understanding iFrames](#understanding-iframes)\n  - [Handling iFrames](#handling-iframes) \n- [Best Practices](#best-practices)\n- [Examples](#examples)\n- [Conclusion](#conclusion)\n- [Contributing](#Contributing)\n- [License](#License)\n- [Contact](#Contact)\n  \n## Introduction\n\nIn Selenium WebDriver, waits are crucial for managing the timing issues that arise during test automation. Properly handling waits ensures that your tests run reliably and reduce the likelihood of errors related to synchronization.\n\n## Consequences of Not Using Waits\n\nFailing to use waits appropriately in your Selenium tests can lead to several issues:\n\n1. **Flaky Tests:** Tests might fail intermittently because they are not waiting for elements to be available or actions to be completed.\n2. **Timing Issues:** Actions may be attempted before elements are fully loaded, causing `NoSuchElementException` or `ElementNotVisibleException`.\n3. **Inconsistent Test Results:** Tests may pass or fail unpredictably depending on the speed of the application and the machine running the tests.\n\n## Types of Waits in Selenium\n\nSelenium WebDriver provides different types of waits to handle various scenarios:\n\n### Thread.sleep\n\n- **Description:** Pauses the execution for a fixed amount of time.\n- **Usage:** `Thread.sleep(milliseconds);`\n- **Pros:** Simple to use.\n- **Cons:** Inefficient as it does not account for the actual state of the element or the application. The test waits for the entire specified time, even if the element is available sooner.\n\n### Implicit Wait\n\n- **Description:** Sets a default wait time for the entire duration of the WebDriver instance.\n- **Usage:** \n ```csharp\n  driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);\n ```\n- **Pros:** Automatically applies to all element lookups, reducing the need for explicit wait statements.\n- **Cons:** Can lead to longer wait times for elements that may not need the full duration, and it's not always suitable for dynamic content.\n\n### Explicit Wait\n- **Description:** Waits for a specific condition to occur before proceeding with the test.\n- **Usage:**\n ```csharp\n WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));\n IWebElement element = wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.Id(\"elementId\")));\n ```\n- **Pros:** More flexible and precise, allowing you to wait for specific conditions such as visibility, presence, or clickability.\n- **Cons:** Requires additional code and setup for each condition you need to wait for.\n  \n### Fluent Wait\n- **Description:** Allows for more fine-grained control over the wait conditions, including polling intervals and ignoring specific exceptions.\n- **Usage:**\n ```csharp\nDefaultWait\u003cIWebDriver\u003e fluentWait = new DefaultWait\u003cIWebDriver\u003e(driver)\n{\n    Timeout = TimeSpan.FromSeconds(10),\n    PollingInterval = TimeSpan.FromSeconds(2)\n};\nfluentWait.IgnoreExceptionTypes(typeof(NoSuchElementException));\n\nIWebElement element = fluentWait.Until(driver =\u003e driver.FindElement(By.Id(\"elementId\")));\n```\n- **Pros:** Highly customizable, suitable for complex conditions and scenarios where you need to adjust polling frequency or handle specific exceptions.\n- **Cons:** More complex to set up compared to implicit and explicit waits.\n  \n## Working with Alerts\nAlerts are modal windows that interrupt the flow of the page, requiring user interaction to proceed. They come in three types: informational, confirmation, and prompt alerts.\n\n### Handling Alerts\n1. **IAlert Interface:** Selenium provides the `IAlert` interface for interacting with alerts.\n2. **Switch to Alert:** Use `driver.SwitchTo().Alert()` to switch context to the alert.\n3. Alert Methods:\n- `Accept()`: Confirms the alert.\n- `Dismiss()`: Cancels the alert.\n- `SendKeys()`: Enters text in prompt alerts.\n- `GetText()`: Retrieves the text of the alert.\n\n### Types of Alerts\n\n- Informational Alerts: Require users to acknowledge by clicking OK.\n ```csharp\n  IAlert alert = driver.SwitchTo().Alert();\nalert.Accept();\n ```\n- Confirmation Alerts: Present users with OK or Cancel options.\n```csharp\n  IAlert alert = driver.SwitchTo().Alert();\nalert.Dismiss();  // To cancel the alert\n ```\n- Prompt Alerts: Require text input before accepting or dismissing.\n ```csharp\n IAlert alert = driver.SwitchTo().Alert();\nalert.SendKeys(\"Test input\");\nalert.Accept();\n ```\n## Working with iFrames\niFrames are HTML elements that allow embedding external content into a webpage. They create isolated environments, and Selenium requires context-switching to interact with elements inside them.\n\n### Understanding iFrames\n- iFrames in HTML: iFrames embed external content, such as media or other web pages, within a parent page.\n- Context Switching: Selenium uses the `SwitchTo().Frame()` method to switch context to the iFrame before interacting with its elements.\n\n### Handling iFrames\nThere are three ways to interact with iFrames in Selenium:\n- By Index:\n```csharp\ndriver.SwitchTo().Frame(0);  // Switches to the first iFrame\n```\n- By ID or Name:\n```csharp\ndriver.SwitchTo().Frame(\"frameId\");  // Switches to iFrame by ID\n```\n- By WebElement:\n```csharp\nIWebElement iframeElement = driver.FindElement(By.Id(\"frameId\"));\ndriver.SwitchTo().Frame(iframeElement);\n```\n- After interacting with the elements inside the iFrame, you can switch back to the parent frame:\n```csharp\ndriver.SwitchTo().DefaultContent();  // Switch back to the main page\n```\n## Best Practices\n1. Prefer Explicit Waits for Specific Conditions: Use explicit waits to handle specific cases where an element needs to meet a particular condition before interacting with it.\n2. Use Implicit Waits for General Waiting: Set an implicit wait to cover general waiting scenarios, but be cautious about potential conflicts with explicit waits.\n3. Avoid Overusing Thread.Sleep: Rely on Thread.Sleep sparingly and only for cases where other waits are not suitable.\n4. Customize Fluent Waits for Complex Scenarios: Use fluent waits when you need more control over the waiting process, especially for dynamic content and polling intervals.\n\n## Examples\n\n### Example: Using Explicit Wait\n```csharp\nWebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));\nIWebElement element = wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.Id(\"submitButton\")));\nelement.Click();\n```\n\n### Example: Using Fluent Wait\n```csharp\nDefaultWait\u003cIWebDriver\u003e fluentWait = new DefaultWait\u003cIWebDriver\u003e(driver)\n{\n    Timeout = TimeSpan.FromSeconds(15),\n    PollingInterval = TimeSpan.FromSeconds(3)\n};\nfluentWait.IgnoreExceptionTypes(typeof(NoSuchElementException));\n\nIWebElement element = fluentWait.Until(driver =\u003e driver.FindElement(By.Id(\"dynamicElement\")));\n```\n## Conclusion\nUsing waits effectively is crucial for stable and reliable Selenium tests. By understanding the different types of waits and applying them appropriately, you can avoid common pitfalls related to timing issues and improve the overall quality of your test automation.\n\n## License\nThis project is licensed under the [MIT License](LICENSE). See the [LICENSE](LICENSE) file for details.\n\n## Contact\nFor any questions or suggestions, please reach out to the course instructor or open an issue in the repository.\n\n---\n### Happy Testing! 🚀\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefruseva88%2Fweb-driver-waits","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstefruseva88%2Fweb-driver-waits","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefruseva88%2Fweb-driver-waits/lists"}