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

उदाहरण
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();
}
}
} आउटपुट
