I am currently creating automated test scripts using selenium-webdriver, phantomJS, and mocha.
The script file I'm working with is a JavaScript file.
My goal is to wait until an element (<a>
) is fully visible before clicking on it.
Let me provide some details:
There are menus and submenus, with the menu being collapsible. Clicking on a menu reveals its corresponding submenus.
The script I have iterates through the menu, clicks on it, then checks the status of the submenu.
for(var iMajor = 2; iMajor <= majorLinkLast ; iMajor++)
{
majorMenuXPath = "//ul[contains(@id, 'side-menu')]/li["+iMajor+"]/a";
if(iMajor != 2)
{
driver.findElement(By.xpath(majorMenuXPath)).click();
driver.manage().timeouts().implicitlyWait(30 * 10000);
}
for(var iMinor = 1; iMinor <= minorSize[iMajor] ; iMinor++)
{
minorMenuXPath = "//ul[contains(@id, 'side-menu')]/li["+iMajor+"]/ul/li["+iMinor+"]/a";
driver.findElement(By.xpath(minorMenuXPath)).isDisplayed().then(function(elem){
console.log(elem);
});
}
This code shows the visibility status of the submenus as either true or false. Some submenus are not visible even after clicking the parent menu, despite using implicit waiting in the driver settings.
I require assistance with the following:
How can I wait until a submenu becomes visible? Once visible, I need to perform certain actions.
Alternatively, how can I make a submenu visible after a set time period?
Below is the HTML structure:
<ul id="side-menu" class="nav">
<li class="nav-header">
<img class="logo" alt="Track Revenue" src="/images/3c4939d.png">
<div class="logo-element"> TR </div>
</li>
<!-- Other menu items omitted for brevity -->
<li>
<a href="#home">
<i class="fa fa-cog"></i>
<span class="nav-label">Settings</span>
<span class="fa arrow"></span>
</a>
<ul class="nav nav-second-level collapse">
<li>
<a href="/profile/">Account</a>
</li>
<li>
<a href="/plan/">Plan Management</a>
</li>
</ul>
</li>
</ul>
Note:
I have basic knowledge of Selenium and require a JavaScript solution. I do not know Java, Python, or C#. Can someone assist me with this issue?