How to test HTML ordered list in Selenium

HOME

<ol>
<html>

<head>
    <title>Numbered List Example</title>
</head>

<body>
    <h2>Ordered List with Numbers</h2>
    <ol>
        <li>JavaScript</li>
        <li>Python</li>
        <li>Java</li>
        <li>C++</li>
        <li>C#</li>
    </ol>
</body>

</html>

package com.example;

import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

import java.time.Duration;
import java.util.List;

public class OrderedList {

    public static void main(String[] args) {

        // Setup the webdriver
        ChromeOptions options = new ChromeOptions();
        WebDriver driver = new ChromeDriver(options);

        // Put an Implicit wait and launch URL
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));

        //Start Browser
        String filePath = "file:///C:/Users/vibha/OneDrive/Desktop/OrderedList.html";
        driver.get(filePath);

        //maximize browser
        driver.manage().window().maximize();

        //Locate the ordered list using its tag name
        WebElement orderedList = driver.findElement(By.tagName(("ol")));

        //Fetch all the list items
        List<WebElement> listItems = orderedList.findElements(By.tagName("li"));

        //Iterate through the list and print the contents
        for (int i = 0; i < listItems.size(); i++) {
            System.out.println(listItems.get(i).getText());
        }

        //Close the main window
        driver.quit();
    }

}

// Setup the webdriver
ChromeOptions options = new ChromeOptions();
WebDriver driver = new ChromeDriver(options);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
String filePath = "file:///C:/Users/vibha/OneDrive/Desktop/OrderedList.html";
driver.get(filePath);
driver.manage().window().maximize();
 WebElement orderedList = driver.findElement(By.tagName(("ol")));
 List<WebElement> listItems = orderedList.findElements(By.tagName("li"));
for (int i = 0; i < listItems.size(); i++) {
            System.out.println(listItems.get(i).getText());
 }

driver.quit();