UrbanPro
true

Learn Selenium from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Wait Handler implementation in WebDriver

Devendra V
18/04/2017 0 0

public void waitForElementPresence(By by) {
        Wait<WebDriver> wait = new WebDriverWait(driver, GLOBAL_TIME_OUT);
        wait.until(ExpectedConditions.presenceOfElementLocated(by));
    }
    
    public void waitForElementPresence(WebElement elmt) {
        Wait<WebDriver> wait = new WebDriverWait(driver, GLOBAL_TIME_OUT);
        wait.until(ExpectedConditions.visibilityOf(elmt));
    }

    public void waitForElementVisibility(By by) {
        Wait<WebDriver> wait = new WebDriverWait(driver, GLOBAL_TIME_OUT);
        wait.until(ExpectedConditions.visibilityOfElementLocated(by));
    }

    public void waitForElementClickable(By by) {
        Wait<WebDriver> wait = new WebDriverWait(driver, GLOBAL_TIME_OUT);
        wait.until(ExpectedConditions.elementToBeClickable(by));
    }
    
    public void waitForPageLoaded() {
        Wait<WebDriver> wait = new WebDriverWait(driver, GLOBAL_TIME_OUT);
        wait.until(checkPageLoadStatus());
    }
    
    public void waitForElementNotVisible(By locator) {
        Wait<WebDriver> wait = new WebDriverWait(driver, GLOBAL_TIME_OUT);
        wait.until(ExpectedConditions.invisibilityOfElementLocated(locator));
    }
    
    public void waitTillTitleContains(String text) {
        Wait<WebDriver> wait = new WebDriverWait(driver, GLOBAL_TIME_OUT);
        wait.until(ExpectedConditions.titleContains(text));
    }
    
    public void waitForWindowPresence(Integer requiredWindowNo){
        Wait<WebDriver> wait = new WebDriverWait(driver, GLOBAL_TIME_OUT);
        wait.until(checkWindowPresence(requiredWindowNo.toString()));
    }
    
    public void sleep(int seconds){
        try {
            Thread.sleep(seconds*1000);
        } catch (InterruptedException e) {
            //Ignore the exception
        }
    }
    
    private Function<WebDriver, Boolean> checkPageLoadStatus() {
        return new Function<WebDriver, Boolean>() {
            public Boolean apply(WebDriver driver) {
                return ((JavascriptExecutor) driver).executeScript(
                        "return document.readyState").equals("complete");
            }
        };
    }

0 Dislike
Follow 0

Please Enter a comment

Submit

Other Lessons for You

Definition of Class and Object in Java
Object - Objects have states and behaviors. Example: A dog has states - colour, name, breed as well as behaviors - barking, eating, sleeping. An object is an instance of a class. Class - A class can be...

Difference between find element () and findelements () in webdriver
findElement Find the first element within the current page using the given "locating mechanism". Returns a single WebElement. findElements Find all elements within the current...

How to toggle b/w frames in webdriver
driver.switchTo().frame() method takes one of the three possible arguments: A number - Select a frame by its (zero-based) index. A name or ID - Select a frame by its name or ID. A previously found...

How to mouse hover on an element in webdriver
Actions action = new Actions(webdriver);WebElement we = webdriver.findElement(By.id("email"));action.moveToElement(we).build().perform();

How to create excel sheets using Java?
HSSFWorkbook workbook = new HSSFWorkbook();HSSFSheet sheet1 = workbook.createSheet("actions");for (int i = 0; i < 10; i++) { sheet1.createRow(i); for (int j = 0; j < 10; j++) { HSSFRow currRow =...
X

Looking for Selenium Classes?

The best tutors for Selenium Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Selenium with the Best Tutors

The best Tutors for Selenium Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more