0
votes
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)

2
Can you make some small changes and update me the status as follows: 1. Remove TestNG environment settings and try executing as a pure Java program? 2. While executing as a TestNG Test/Suite with Test annotation you must not use the method name as "main", change it to something else and update me the status.DebanjanB

2 Answers

0
votes

I think the element could not be found in your html page, maybe your xpath is incorrect. you could try checking it using chrome developer tools > console tab, then type $x(". //[@id='gs_htif0']") and see whether it returns anything. Maybe your xpath should be "//[@id='gs_htif0']"

0
votes

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.