Identifying auto-suggestion lists and storing them can be achieved using iterator. Couple of examples shown below demonstrate iterators and their use on auto-complete.
e.g.,
1|
driver.get(baseUrl+"http://www.indiabookstore.net/");
driver.findElement(By.id("searchBox")).sendKeys("sam");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
WebElement table = driver.findElement(By.className("acResults"));
List<WebElement> rowlist = table.findElements(By.tagName("li"));
System.out.println("Total No. of list: "+rowlist.size());
Iterator<WebElement> i = rowlist.iterator();
System.out.println("Storing Auto-suggest..........");
while(i.hasNext())
{
WebElement element = i.next();
System.out.println(element.getText());
}
e.g.,
1|
driver.get(baseUrl+"http://www.indiabookstore.net/");
driver.findElement(By.id("searchBox")).sendKeys("sam");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
WebElement table = driver.findElement(By.className("acResults"));
List<WebElement> rowlist = table.findElements(By.tagName("li"));
System.out.println("Total No. of list: "+rowlist.size());
Iterator<WebElement> i = rowlist.iterator();
System.out.println("Storing Auto-suggest..........");
while(i.hasNext())
{
WebElement element = i.next();
System.out.println(element.getText());
}
2|
driver.get(baseUrl+"https://www.google.co.in/");
driver.findElement(By.id("gbqfq")).sendKeys("Sams");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
WebElement table = driver.findElement(By.className("gssb_m"));
List<WebElement> rows = table.findElements(By.tagName("span"));
System.out.println("Total no. of rows: "+ rows.size());
Iterator<WebElement> i = rows.iterator();
while(i.hasNext()) {
WebElement row = i.next();
System.out.println(row.getText());
}
Thread.sleep(4000);
rows.get(1).click();
Thread.sleep(5000);
Alternate Concept for iteration
List<WebElement> listitems = driver.findElements(By.id("value"));
for(WebElement temp: listitems) // temp is the declared variable name
{
System.out.println((temp.findElement(By.tagName("value")).getText()));
}
driver.findElement(By.id("gbqfq")).sendKeys("Sams");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
WebElement table = driver.findElement(By.className("gssb_m"));
List<WebElement> rows = table.findElements(By.tagName("span"));
System.out.println("Total no. of rows: "+ rows.size());
Iterator<WebElement> i = rows.iterator();
while(i.hasNext()) {
WebElement row = i.next();
System.out.println(row.getText());
}
Thread.sleep(4000);
rows.get(1).click();
Thread.sleep(5000);
Alternate Concept for iteration
List<WebElement> listitems = driver.findElements(By.id("value"));
for(WebElement temp: listitems) // temp is the declared variable name
{
System.out.println((temp.findElement(By.tagName("value")).getText()));
}
Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
ReplyDeleteBig Data Hadoop training in electronic city
Python Training in electronic city
DataScience with Python Training in electronic city
AWS Training in electronic city
Big Data Hadoop Training in electronic city
Devops Training in electronic city
blockchain Training in electronic city
Hibernate Training in electronic city
Data science Training in Electronic City
Selenium with python Training in Electronic City