I have a menu in the application when you click on any menu item it gives you a list which looks like this:
<ul class="list-unstyled components">
<ul class="list - unstyled components">
<li class="active"><a href="#homeSubmenu" data-toggle="collapse" aria-expanded="false" class="dropdown-toggle blueMenu">
<i class="nav-icon fa fa-angle-double-right"></i>
Audit Reports Tracking</a>
</li>
<li><a href="/Pages/Main_Page/Audit_Report.aspx?pageId=10" class="nav-link">
<i class="fa fa-angle-double-right"></i> <span style="font-size: small">
Audit Report Entry</span> </a>
</li>
<li><a href="/Pages/Monitor/Audit_Report_Monitor.aspx?pageId=10" class="nav-link">
<i class="fa fa-angle-double-right">
</i> <span style="font-size: small">
Audit Escalation Monitor</span> </a>
</li>
<li><a href="/Pages/FinancialLoss/FinancialImpactsReport.aspx?pageId=10" class="nav-link">
<i class="fa fa-angle-double-right"></i>
<span style="font-size: small">
Financial Impacts Report</span> </a>
</li>
</ul>
</ul>
So i wrote a code like that : to traverse the sub menu no matter what the size of the sub menu in case it became shorter or longer in the future or for different user role logins becaus in the application the sub menus differes for each user role.
Here's the code:
WebElement auditMenu = driver.findElement(By.xpath("//*[@id=\"MainMenuDiv\"]/ul"));
List<WebElement> links = auditMenu.findElements(By.tagName("li"));
for (int i = 1; i < links.size(); i++) {
System.out.println(links.get(i).getText());
if (links.get(i).getText().equals("Audit Escalation Monitor")) {
System.out.println("hi");
}
}
The if Statement is not executing and I don't know what is the reason for it.
Thanks in advance