हम Selenium WebDriver में एलिमेंट मौजूद होने तक एक्सप्लिसिट वेट का उपयोग करके प्रतीक्षा कर सकते हैं। यह मुख्य रूप से तब उपयोग किया जाता है जब किसी एलिमेंट के पेज पर उपलब्ध होने के लिए सिंक्रनाइज़ेशन समस्या होती है।
WebDriverWait और ExpectedCondition क्लासेस का उपयोग एक्सप्लिसिट वेट कार्यान्वयन के लिए किया जाता है। हमें WebDriverWait का एक ऑब्जेक्ट बनाना होगा जो ExpectedCondition क्लास के मेथड्स को इनवोक करेगा।
WebDriver एक निर्दिष्ट समय तक अपेक्षित मानदंड पूरा होने की प्रतीक्षा करता है। समय समाप्त होने के बाद, एक एक्सेप्शन फेंक दिया जाता है। एलिमेंट के मौजूद होने की प्रतीक्षा करने के लिए, हमें अपेक्षित स्थिति - ElementExists का उपयोग करना होगा।
सिंटैक्स
WebDriverWait w = new WebDriverWait(driver, TimeSpan.FromSeconds(20)); w.Until(ExpectedConditions.ElementExists(By.TagName("h1")));आइए पेज पर टेक्स्ट - About Careers at Tutorials Point के उपलब्ध होने की प्रतीक्षा करने का प्रयास करें −

उदाहरण
using NUnit.Framework; using OpenQA.Selenium; using OpenQA.Selenium.Firefox; using System; using OpenQA.Selenium; using OpenQA.Selenium.Support.UI; namespace NUnitTestProject2{ public class Tests{ String url ="https://www.tutorialspoint.com/about/about_careers.htm"; IWebDriver driver; [SetUp] public void Setup(){ //creating object of FirefoxDriver driver = new FirefoxDriver(""); } [Test] public void Test2(){ //URL launch driver.Navigate().GoToUrl(url); //identify element then click IWebElement l = driver.FindElement(By.XPath("//*[text()='Careers']")); l.Click(); //expected condition of ElementExists WebDriverWait w = new WebDriverWait(driver, TimeSpan.FromSeconds(20)); w.Until(ExpectedConditions.ElementExists(By.TagName("h1"))); //identify element then obtain text IWebElement m = driver.FindElement(By.TagName("h1")); Console.WriteLine("Element text is: " + m.Text); } [TearDown] public void close_Browser(){ driver.Quit(); } } }आउटपुट
