Quality Testing

Quality is delighting customers

How to use WebDriverWait for various methods in Selenium Junit?

I have various methods in my code in which i need to use WebDriverWait.Usually we declare it in main method like: WebDriverWait mywait= new WebDriverWait(driver,25). While using junit in selenium there is no main method,so how can i use WebDriverWait for webelements in various methods in my code???

Views: 267

Reply to This

Replies to This Discussion

Try this ;

WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(1, TimeUnit.MILLISECONDS);
driver.get("http://www.rambler.ru");
driver.quit();

or

WebDriverWait wait = new WebDriverWait(webDriver, timeoutInSeconds);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id/span>locator>));

or
wait.until(ExpectedConditions.elementToBeClickable(By.id/span>locator>));

refer the below urls, i think this will helpfull to u,
-correct me if am wrong means :-)




hi

you can use it any where

wait.until(ExpectedConditions.any method which returns boolen value

 Please see my code below. I want to use explicit wait and i have written different methods in Junit for locators but i am getting nullpointer exception when i run the code,can you explain me where i am going wrong??

public class test{
        private static WebDriver driver=null ; 

public void waitForID(String id)
          {         
           WebDriverWait wait = new WebDriverWait(driver, 60);      
           wait.until(ExpectedConditions.presenceOfElementLocated(By.id(id)));
           
          }
     
      
      public void waitForxpath(String xpath)
      {         
       WebDriverWait wait = new WebDriverWait(driver, 60);      
       wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(xpath)));
       
      }
        
      public void waitForname(String name)
      {         
       WebDriverWait wait = new WebDriverWait(driver, 60);      
       wait.until(ExpectedConditions.presenceOfElementLocated(By.name(name)));
       
      }

@Test             
          public void testcase1() throws InterruptedException {  
       
              waitForname("0.2.1.3.3.6.5.7.2.1.0.1.5.20.3.3.5");
            driver.findElement(By.name("0.2.1.3.3.6.5.7.2.1.0.1.5.20.3.3.5")).click();
              
}

}

RSS

TTWT Magazine


Advertisement

Advertisement

Advertisement

Advertisement

© 2021   Created by Quality Testing.   Powered by

Badges  |  Report an Issue  |  Terms of Service