I have 10 different pages contain different links. How to click on all the links?
Conditions are : i) I don\'t know how many links are there ii) I want to count and
Capture and Navigate all the Links on Webpage
Iterator and advanced for loop can do similar job; However, the inconsistency on page navigation within a loop can be solved using array concept.
private static String[] links = null;
private static int linksCount = 0;
driver.get("www.xyz.com");
List linksize = driver.findElements(By.tagName("a"));
linksCount = linksize.size();
System.out.println("Total no of links Available: "+linksCount);
links= new String[linksCount];
System.out.println("List of links Available: ");
// print all the links from webpage
for(int i=0;i
1| Capture all links under specific frame|class|id and Navigate one by one
driver.get("www.xyz.com");
WebElement element = driver.findElement(By.id(Value));
List elements = element.findElements(By.tagName("a"));
int sizeOfAllLinks = elements.size();
System.out.println(sizeOfAllLinks);
for(int i=0; i elements = element.findElements(By.tagName("a"));
return elements.get(index);
}
2| Capture all links [Alternate method]
driver.get(baseUrl + "https://www.google.co.in");
List all_links_webpage = driver.findElements(By.tagName("a"));
System.out.println("Total no of links Available: " + all_links_webpage.size());
int k = all_links_webpage.size();
System.out.println("List of links Available: ");
for(int i=0;i
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("https://www.google.co.in/")
list_links = driver.find_elements_by_tag_name('a')
for i in list_links:
print i.get_attribute('href')
driver.quit()