How to click a random link in a web element
<p>I am currently training in Selenium. The objective of the task is to:</p>

<ol>
<li>Navigate to a random Wikipedia page</li>
<li>Pick a random category from the page's list of categories </li>
<li>Select a random article from the list of pages in the selected category</li>
<li>Output the compared differences between the categories of the original random page and the second one.</li>
</ol>

<p>I have gotten all the way to the category page, but for some reason the code wont click on a random article within that page.</p>

<p>Here is my current code for the category page</p>

<pre><code>        //Navigating to the category list at the bottom of the page
        WebElement Category = driver.findElement(By.id("mw-normal-catlinks"));
        Category.click();
        //finds a random link in the category list
        Random r = new java.util.Random();
        List&lt;WebElement&gt; links = driver.findElements(By.xpath("//div[@class = 'mw-category']"));    
        //picks a random link
        WebElement randomElement = links.get(r.nextInt(links.size()));
        randomElement.click();

        WebElement newCategory = driver.findElement(By.xpath("//div[@class= 'mw-category-generated']//div[@class= 'mw-category']"));
        newCategory.click();
        Random n = new java.util.Random();
        List&lt;WebElement&gt; ArticleLinks = driver.findElements(By.xpath("//div[@class= 'mw-category-generated']//div[@class= 'mw-category']"));
        WebElement randomElement2 = articleLinks.get(n.nextInt(articleLinks.size()));
        randomElement2.click();
</code></pre>