2
votes
 @Test
      public void TC8() {

          driver.findElement(By.id("id_username")).sendKeys("admin");
          driver.findElement(By.id("id_password")).sendKeys("admin");
          driver.findElement(By.cssSelector("button,input[type='button']")).click();
          Reporter.log("TC101 > Login successfully to crossfraudet");
      }

     @Test
     public void TC9() {

         Assert.assertEquals("USER PROFILE", "USER PROFILE");
         Assert.assertEquals("SETTINGS", "SETTINGS");
         Assert.assertEquals("DASHBOARD", "DASHBOARD");
         Assert.assertEquals("ADMINISTRATION", "ADMINISTRATION");
     }

      @Test
      public void TC10() {

        wait=new WebDriverWait(driver,30);
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".icon-users"))).click();
    wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("#menuList > li.dropdown.open > ul > li:nth-child(3) > a"))).click();
    Reporter.log("TC10 > Click on User Profile > Profiles");   
      }

[TestNG] Running:
C:\Users\Murali\AppData\Local\Temp\testng-eclipse-609099432\testng-customsuite.xml

PASSED: TC8 PASSED: TC9
FAILED: TC10

org.openqa.selenium.TimeoutException: Timed out after 30 seconds waiting for visibility of element located by By.selector: .icon-users Build info: version: '2.43.1', revision: '5163bce', time: '2014-09-10 16:27:33'

It shows the above error. If I use driver.findElement it shows No such element exception. If I user wait.until(ExpectedCondition.presenceOfElementLocated), it shows timeoutexception. How could I solve this issue

1
First of all, is the element u are looking for is displayed with in 30 sec or not? Mostly it is because of the element is not visible within max time mentioned. Try verify with Thread.Sleep - HemaSundar
make sure the element is visible within 30 seconds - Rishi Khanna

1 Answers

1
votes

wait.until() will throw TimeoutException even though the element is not present. But if you try to catch the exception and print its cause, you will be able to see the exact cause of the exception. It could be org.openqa.selenium.NoSuchElementException. Please try the below code:

WebDriverWait wait=new WebDriverWait(driver,30);
try {
       wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".icon-users"))).click();
} catch (TimeoutException exception) {
    System.out.println(exception.getCause().toString());
}