Selenium Webdriver practical, clicking on a particular footer link on ebay site.
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 GetEbayLinks {
public static WebDriver driver = null;
public static void main(String[] args) {
driver = new FirefoxDriver();
// going to ebay.com
driver.get("http://ebay.com");
// getting the footer section box element
WebElement sellLinks = driver.findElement(By
.xpath(".//*[@id='gf-BIG']/table/tbody/tr/td[2]/ul"));
// Listing elements from that footer box
List<WebElement> listLinks = sellLinks.findElements(By.tagName("a"));
System.out.println(listLinks.size());
// For loop over the links in that footer box.
for (int i = 0; i < listLinks.size(); i++) {
String value = sellLinks.findElements(By.tagName("a")).get(i)
.getText();
System.out.println(value);
// checking if a particular link is present. "mobile apps"
if (value.contains("Mobile apps")) {
System.out.println("here");
// link found and clicking on that link.
sellLinks.findElements(By.tagName("a")).get(i).click();
// breaking the for loop here
break;
}
}
driver.quit();
}
}
No images available.