I need help with a menu that displays a list on mouse hover, and I'm trying to click on "Logout". However, the code I've written so far is not giving me the desired result.
This is the Java code I have:
public void logout() throws Exception {
WebElement profileDropdown = driver.findElement(By.className("profile-dropdown"));
List<WebElement> elems = driver.findElements(By.cssSelector("ul>li>a"));
elems.get(5).click();
}
I've tried different approaches, as you can see from the commented lines of code. Unfortunately, nothing seems to work for me.
Below is the HTML code I'm working with:
<div style="display: none;" class="profile-dropdown">
<ul>
<li><a href="https://consumers.keenu.pk/index.php/profile/">My Profile <!--<label id="lblProfilePercentage">0</label>--></a></li>
<li><a href="https://consumers.keenu.pk/index.php/transactionhist/">Transaction History</a></li>
<li><a href="https://consumers.keenu.pk/index.php/customer-care/helpline">Helpline</a></li>
<li><a href="https://consumers.keenu.pk/index.php/pin-pass/">PIN & Password</a></li>
<li><a href="https://consumers.keenu.pk/index.php/settings/">Favorites</a></li>
<li><a href="#" id="lnkLogout" style="cursor:pointer">Log Out</a></li>
</ul>
</div>
The code is able to locate the "profile-dropdown" element but encounters an exception when trying to find the list element.
If anyone could provide some assistance, it would be greatly appreciated.