Thursday 8 August 2013

Get all the links from a page and print target for each link as follows in Selenium

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;


public class Google_search {


public static void main(String[] args) throws InterruptedException  {

WebDriver dr= new  FirefoxDriver();
dr.get("http://google.com");

dr.findElement(By.xpath("//input[@id='gbqfq']")).sendKeys("selenium");



Thread.sleep(10000L);
WebElement  fr=dr.findElement(By.xpath("//div[@id='rcnt']"));
List<WebElement> friends_list=fr.findElements(By.tagName("a"));
 for(WebElement link : friends_list)
System.out.println(link.getAttribute("href"));



}

}

No comments:

Post a Comment