ওয়েব পৃষ্ঠার একটি নির্দিষ্ট উপাদানে স্পষ্ট অপেক্ষা প্রয়োগ করা হয়৷ শর্ত সন্তুষ্ট না হওয়া পর্যন্ত এটি মৃত্যুদন্ড কার্যকর করা থামাতে হবে। স্পষ্ট অপেক্ষাও একটি গতিশীল কারণ যদি অপেক্ষার সময়টি পনের সেকেন্ড হয় এবং শর্তগুলি (যেমন একটি উপাদান ক্লিকযোগ্য, দৃশ্যমান বা নির্বাচনযোগ্য হওয়ার জন্য অপেক্ষা করা ইত্যাদি) এই নির্দিষ্ট সময়ের আগে সন্তুষ্ট হয়, নিয়ন্ত্রণটি পরবর্তী ধাপে চলে যাবে .
স্পষ্ট অপেক্ষা আরও কাস্টমাইজযোগ্য কারণ আমরা শর্তের জন্য এটি সেট আপ করতে পারি। সুস্পষ্ট অপেক্ষার জন্য প্রত্যাশিত কিছু শর্তের তালিকা নীচে তালিকাভুক্ত করা হয়েছে -
-
textToBePresentInElement()
সিনট্যাক্স
w.until(ExpectedConditions.textToBePresentInElement(By.id(“<<id expression>>“), “Tutorialspoint”));
-
textToBeClickable()
সিনট্যাক্স
w.until(ExpectedConditions.textToBeClickable(By.id(“<<id expression>>“)));
-
AlertisPresent()
সিনট্যাক্স
w.until(ExpectedConditions.alertisPresent())= null);
-
frameToBeAvailableAndSwitchToIt()
সিনট্যাক্স
w.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.id(“<<frame id >>“)));
এক্সপ্লিসিট বাস্তবায়নের ক্ষেত্রে জটিল, তবে এটি কার্যকর করার গতিকে প্রভাবিত করে না এবং একটি পৃষ্ঠার একটি নির্দিষ্ট উপাদানের জন্য প্রযোজ্য।
সুস্পষ্ট অপেক্ষায়, একবার সর্বাধিক সময় পেরিয়ে গেলে, ElementNotVisibleException নিক্ষেপ করা হয়৷
উদাহরণ
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.support.ui.Wait;
public class Explictwt {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\ghs6kor\\Desktop\\Java\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
String url = "https://www.tutorialspoint.com/index.htm";
driver.get(url);
//implicit wait with time in seconds applied to each elements
driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);
//Clicking on Coding Ground link
driver.findElement(By.xpath("//span[text()=’Coding Ground’]")).click();
// explicit wait declaration
WebDriverWait w = new WebDriverWait(driver,10);
// condition to wait for with textToBePresentInElement method
w.until(ExpectedConditions.textToBePresentInElement(By.xpath("//img[@title=’Whiteboard’]"),” Whiteboard”));
driver.quit();
}
}