Search code examples
seleniumtestingtimeoutexception

Timeout error in TestNG


package ant;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;


public class NewTestNG {
public WebDriver driver;

@BeforeMethod
public void LAunchbrowser() {
  driver = new FirefoxDriver();
  driver.get("https://www.google.co.in/");
  //driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

}
  @Test
  public void main() {
  Actions action = new Actions(driver);
  WebDriverWait wait = new WebDriverWait (driver, 20);
  WebElement w= 
   wait.until(ExpectedConditions.elementToBeClickable(By.xpath(".//*
  [@id='gs_htif0']")));
   WebElement a=   driver.findElement(By.xpath(".//*[@id='gs_htif0']"));    
   action.moveToElement(a).click().sendKeys("Shirt").build().perform(); 
  driver.findElement(By.xpath("//div[@value='Search']")).click();


 }}

getting below error:

FAILED: main org.openqa.selenium.TimeoutException: Timed out after 20 seconds waiting for element to be clickable: By.xpath: .//*[@id='gs_htif0'] Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:37:09' Driver info: org.openqa.selenium.firefox.FirefoxDriver Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=46.0, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}] Session ID: 93e46eb2-2ba1-479b-9bfd-c56178d7eb7c at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:80) at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:261) at ant.NewTestNG.main(NewTestNG.java:28)


Solution

  • Replace your @Test method code with below mentioned code.

        WebDriverWait wait = new WebDriverWait (driver, 20);
        WebElement w= 
                wait.until(ExpectedConditions.elementToBeClickable(By.id("lst-ib")));
        w.sendKeys("Shirt"); 
        driver.findElement(By.id("_fZl")).click();
    

    Let me know if it works for you.