Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to wait a page before going to another page in Selenium WebDriver using Java?

I am new in Selenium. I am using Selenium WebDriver with Java. I'm using eclipse as IDE. I have written some code for Login page and it is run successfully. Now I want to go to desired page after successful login, but I want to wait for few time before transiting another page. How can I wait a page before loading another page?

like image 314
Nasrin Naher Avatar asked Aug 22 '13 10:08

Nasrin Naher


1 Answers

As far as I know, there are 3 ways:

  1. Implicit wait: (It's applicable for all elements on the page)

    driver.manage().timeouts().implicitlyWait(A_GIVEN_NUMBER, TimeUnit.SECONDS);

  2. Explicit wait: (Applicable for a particular element)

    WebDriverWait.until(CONDITION_THAT_FINDS_AN_ELEMENT);

More specific code is as below:

WebDriverWait wait = new WebDriverWait(driver, 40);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));
  1. Using Thread:

    Thread.sleep(NUMBER_OF_MILLIS);

like image 163
M. Abbas Avatar answered Oct 19 '22 05:10

M. Abbas