The below code is for searching a text automatically from the auto
suggest; mainly for a list item.
Thread.sleep(3000);
List <WebElement> listItems = driver.findElements(By.xpath("//div[@class='acResults']//li"));
// List <WebElement> listItems =
driver.findElements(By.xpath("//div[contains(@class,'acResults')]//li"));
driver.get("http://www.indiabookstore.net");
driver.findElement(By.id("searchBox")).sendKeys("Alche");Thread.sleep(3000);
List <WebElement> listItems = driver.findElements(By.xpath("//div[@class='acResults']//li"));
//List <WebElement> listItems =
driver.findElements(By.cssSelector(".acResults li"));
// List<WebElement> link = driver.findElement(By.id("Element")).findElements(By.tagName("li"));
listItems.get(0).click();
driver.findElement(By.id("searchButton")).click();
NOTE: get(0) is the first option displayed on searching keywords
get(1) is the second option
displayed on searching keywords.
thanks - http://letusnotifyyou.com/print-selenium-autosuggestion-text/
ReplyDelete