If I got you right you have the case like this:

If yes, then you can define all the items in the container in the way Selenium provides to define page objects and then iterate through the items from that container. Here is the sample PageWithSideNav
class implementing the approach against https://www.w3schools.com/ page:
package ar.test;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import java.util.List;
import java.util.stream.Collectors;
public class PageWithSideNav {
@FindBy(xpath = "//nav[@id='mySidenav']//a")
List<WebElement> sideNavItems;
public void clickItemWithTextJava8(String text) {
List<WebElement> filteredList = sideNavItems.stream().filter(s ->
s.getText().equals(text)
).collect(Collectors.toList());
if (filteredList.size() != 1) {
// Excpetion case. Handle.
} else {
filteredList.get(0).click();
}
}
public void clickItemWithTextJavaPre8(String text) {
for (WebElement element : sideNavItems) {
if (element.getText().equals(text)) {
element.click();
return;
}
}
// Exception case. Handle.
}
}
It actually introduces two identical methods demonstrating how could the approach look like in Java8 and later (lambda style) and in pre-Java8. Below is the example on how to use this PageWithSideNav
:
package ar.test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.PageFactory;
public class Main {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "E:/Dev/WebDrivers/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.w3schools.com");
PageWithSideNav page = PageFactory.initElements(driver, PageWithSideNav.class);
page.clickItemWithTextJava8("Learn Colors");
driver.navigate().back();
page.clickItemWithTextJavaPre8("Learn Graphics");
driver.close();
}
}