
The goal of this program is to visit https://www.cia.gov/the-world-factbook/countries/ and grab the links contained in the table for all 262 countries. I am using Selenium to accomplish this but I am running into issues grabbing more than the first page of results.
My test code is the following:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import java.util.ArrayList;
public static void main(String[] args){
WebDriver driver = new HtmlUnitDriver();
driver.get("https://www.cia.gov/the-world-factbook/countries/");
ArrayList<WebElement> links = (ArrayList<WebElement>) driver.findElements(By.className("inline-link"));
System.out.println(links);
WebElement button = driver.findElement(By.cssSelector("span[class='pagination__arrow-right']"));
button.click();
links = (ArrayList<WebElement>) driver.findElements(By.className("inline-link"));
System.out.println(links);
driver.close();
}
The driver successfully finds the button but after it is clicked and I grab the next set of links, they are still the same instead of being updated. I'm new to using Selenium and am not sure why the driver does not pick up the new table changes. The first screen shot is the button on the page. The second screenshot is the table. When looking at it, Croatia is the inline-link. When the next button is pressed, that value changes to salvadore.