WebDriver- ը սպասում է էջին `օրինակներ բեռնելու համար

WebDriver- ի այս ձեռնարկում մենք նայում ենք, թե ինչպես սպասել էջի բեռնման ավարտին, նախքան այլ գործողություններ կատարելը: Java- ում երկու օրինակ սպասում է էջի բեռնմանը WebDriver- ում:



Սպասեք էջի բեռնմանը - Մեթոդ # 1

import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.ExpectedCondition; import org.openqa.selenium.support.ui.WebDriverWait; import org.testng.Assert; public class WaitForPageExample {
WebDriver driver = new FirefoxDriver();
public void waitForPageLoaded() {
ExpectedCondition expectation = new


ExpectedCondition() {



public Boolean apply(WebDriver driver) {




return ((JavascriptExecutor) driver).executeScript('return document.readyState').toString().equals('complete');



}


};
try {

Thread.sleep(1000);

WebDriverWait wait = new WebDriverWait(driver, 30);

wait.until(expectation);
} catch (Throwable error) {

Assert.fail('Timeout waiting for Page Load Request to complete.');
}
} }


Սպասեք էջի բեռնմանը - Մեթոդ # 2

import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.support.ui.ExpectedCondition; import org.openqa.selenium.support.ui.WebDriverWait; public class WaitForPageExample {
public void waitForLoad(WebDriver driver) {
ExpectedCondition pageLoadCondition = new


ExpectedCondition() {



public Boolean apply(WebDriver driver) {




return ((JavascriptExecutor)driver).executeScript('return document.readyState').equals('complete');



}


};
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(pageLoadCondition);
} }

Հետագա ընթերցում.