1

I am having trouble clicking on the New Events drop down menu resulting from hovering the mouse over a main menu option Events. The issue with the menu resulting from hovering the mouse is that the sub menu elements (All Events and New Events) are not available for selection until the drop down menu appears. When i run my script, the presence of the element cannot be located.

Below is a snippet of my HTML

<div id="navigation">
    <nav id="top-nav">
      <ul id="left-nav" class="left-navbar">
        <a class="no-hover" href="mainMenu.html">
        <li class="border-right">
          <a id="EventsMenu" href="eventsList.html">Events ▼</a>
            <ul class="submenu">
                <li>
                    <a id="ev.eventList.vadm" href="eventsList.html">All Events</a>
                </li>
               <li>
                   <a id="ev.newEventList.vadm" href="newEventsList.html">New Events</a>
               </li>
            </ul>
         </li>
       </ul>
    </nav>
</div>

And here is the part of the selenium script that fails (using PhantomJS):

WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id='EventsMenu']")));  // locating the main menu

WebElement menu = driver.findElement(By.xpath("//*[@id='EventsMenu']"));
Actions builder = new Actions(driver); 
builder.moveToElement(menu).build().perform();

wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id='ev.newEventList.vadm']/tbody/tr[2]/td[1]/a[1]"))); 

WebElement menuOption = driver.findElement(By.xpath("//*[@id='ev.newEventsList.vadm']/tbody/tr[2]/td[1]/a[1]"));
menuOption.click();
1
  • Not able to run your HTML pls provide working app link if possible, or css, Or screenshot of the drop downs...I can help you with this
    – Rohhit
    Commented Jul 22, 2017 at 5:45

1 Answer 1

2

Try doing this and let me know if it works :

    WebDriverWait wait = new WebDriverWait(driver, 5);
    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id='EventsMenu']")));  // locating the main menu

    WebElement menu = driver.findElement(By.xpath("//*[@id='EventsMenu']"));
    Actions builder = new Actions(driver); 
    builder.moveToElement(menu).build().perform();

    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id='ev.newEventList.vadm']/tbody/tr[2]/td[1]/a[1]"))); 

    WebElement menuOption = driver.findElement(By.xpath("//*[@id='ev.newEventsList.vadm']/tbody/tr[2]/td[1]/a[1]"));
    builder.moveToElement(menuOption).click().build().perform();
1
  • Thank you for the suggestion Rohhit. I got it to work in Firefox by initializing the second (hovered) menu (menu1) and then calling it like this: with:builder.moveToElement(menu).moveToElement(menu1).click().perform(). However, i am still having issues with PhantomJS, which i will further explore.
    – kokodee
    Commented Aug 5, 2017 at 21:13

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.