Selenium WebDriver: Working with a AutoSuggest box

In this blog post , let us see how Mr.Web Driver is going to handle an Auto Suggest box .
















First and foremost point to be noted  is when you type a character(or) text  in the auto suggest box.we need to wait till application shows up some suggestions starting (or) containing the typed character.

In the below illustrated example , Mr.Web Driver gives us an option to wait(using Explicit wait) until the suggestions are visible.

public class Suggestbox {

WebDriver driver=new FirefoxDriver();
  @Test
  public void cool() throws InterruptedException {

 driver.get("http://gwt.googleusercontent.com/samples/Showcase/Showcase.html#!CwSuggestBox");

 driver.manage().window().maximize();


 WebDriverWait wait=new WebDriverWait(driver,10);

 wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.id("gwt-debug-cwSuggestBox")));
 //ENTER SOME VALUE IN SUGGEST BOX
 driver.findElement(By.id("gwt-debug-cwSuggestBox")).sendKeys("a");


 wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//td[contains(@role,'menuitem')]")));
 List<WebElement> t1=driver.findElements(By.xpath("//td[contains(@role,'menuitem')]"));


 System.out.println("count of items in the suggestions table is:"+t1.size());

 for(WebElement item:t1)
 {
 System.out.println(item.getText().toString());
 }

 driver.close();
driver.quit();

  }
}

Appreciate your feedback (or) comments :)

Comments

Popular posts from this blog

Cypress Cheat Sheet

Selenium WebDriver-Working with Listbox and Multi-Select Listbox

Selenium WebDriver -Handling JavaScript alerts