Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. import org.openqa.selenium.JavascriptExecutor;
  2. import org.openqa.selenium.WebDriver;
  3.  
  4. import org.openqa.selenium.firefox.FirefoxDriver;
  5. import org.openqa.selenium.support.ui.ExpectedCondition;
  6. import org.openqa.selenium.support.ui.WebDriverWait;
  7. import org.testng.Assert;
  8.  
  9. public class WaitForPageLoad {
  10.  
  11. WebDriver driver = new FirefoxDriver();
  12.  
  13. public void waitForPageLoaded() {
  14. ExpectedCondition<Boolean> expectation = new
  15. ExpectedCondition<Boolean>() {
  16. public Boolean apply(WebDriver driver) {
  17. return ((JavascriptExecutor) driver).executeScript("return document.readyState").toString().equals("complete");
  18. }
  19. };
  20. try {
  21. Thread.sleep(1000);
  22. WebDriverWait wait = new WebDriverWait(driver, 30);
  23. wait.until(expectation);
  24. } catch (Throwable error) {
  25. Assert.fail("Timeout waiting for Page Load Request to complete.");
  26. }
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement