Friday, 4 August 2017

Code Example - Get Links

package com.practiceCode;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.annotations.Test;

/**
 * @Blog Name : Selenium Code Example
 * @author Deepak Gupta
 * @Created Date 4-08-2017
 *
 */
public class FindNoOfLinks extends SuperTestNG {

@Test
public void test() throws InterruptedException {
try {
driver.get("http://only-testing-blog.blogspot.in/2013/09/testing.html");
List<WebElement> no = driver.findElements(By.tagName("a"));
int nooflinks = no.size();
System.out.println("Number of Links : " + nooflinks);
for (WebElement pagelink : no) {
String linktext = pagelink.getText();
String link = pagelink.getAttribute("href");
System.out.println(linktext + " ->");
System.out.println(link);
}
} catch (Exception e) {
System.out.println("error " + e);
}

}

}

No comments:

Post a Comment

Code Example - File Download By Robot Class In Firefox Browser

Exported from Notepad++ package com . practiceCode ; import java . awt . AWTException ; import java . awt . Robot ; import j...