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 GoogleSearch {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.co.in");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.findElement(By.name("q")).sendKeys("Selenium");
WebElement table= driver.findElement(By.className("sbsb_b"));
List<WebElement> list = table.findElements(By.tagName("li"));
for (WebElement options : list) {
Thread.sleep(1000);
System.out.println(options.getText());
if (options.getText().trim().contains("selenium ide")) {
Thread.sleep(1000);
options.click();
}
}
}
}
No comments:
Post a Comment