How to get auto populated Search results using selenium webdriver

How to get auto populated Google search results?

package selenium_examples;

import java.util.Iterator;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;


public class Sample {

public static void main(String[] args)
{
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.co.in");
driver.findElement(By.id("gbqfq")).sendKeys("Testing");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
 
WebElement table = driver.findElement(By.className("gssb_m"));    
List rows = table.findElements(By.tagName("span")); 
System.out.println("Total no. of rows: "+ rows.size());
Iterator i = rows.iterator();  
while(i.hasNext()) {
 WebElement row = i.next();
 System.out.println(row.getText());
}

     
}

       }


Output:-

Total no. of rows: 4
testing
testing tools
testingken
testing interview questions

webdriver autocomplete script

 




 

No comments:

Related Posts Plugin for WordPress, Blogger...