title: Selenium webdriver- Unable to click on submenu - amazon.in
body: <p>I am trying to click on a submneu in amazon.in
  I could expand the main menu. but can't click on sub menu. I tried two methods. But its showing errors.</p>
  
  <p>Mail category html  code:</p>
  
  <pre><code>&lt;li class="nav_pop_li nav_cat nav_divider_before" id="nav_cat_2"&gt;Books&lt;/li&gt;
  </code></pre>
  
  <p>Subcategory html </p>
  
  <pre><code>&lt;a href="/Books/b/ref=nav_shopall_books_all?ie=UTF8&amp;amp;node=976389031" class="nav_a nav_item"&gt;All Books&lt;/a&gt;
  </code></pre>
  
  <p>I used the following methods</p>
  
  <p>Method 1</p>
  
  <pre><code>driver.get("http://amazon.in");
      driver.manage().window().maximize();
      Actions actions = new Actions(driver);
              WebElement moveonmenu = driver.findElement(By.xpath("//li[@id='nav_cat_2']"));
              actions.moveToElement(moveonmenu).moveToElement(driver.findElement(By.xpath("//a[@class='nav_a nav_item']"))).click().perform();
  </code></pre>
  
  <p>Method 2</p>
  
  <pre><code>driver.get("http://amazon.in");
          driver.manage().window().maximize();
      //locate the menu to hover over using its xpath
              WebElement menu = driver.findElement(By.xpath("//li[@id='nav_cat_2']"));
  
              //Initiate mouse action using Actions class
              Actions builder = new Actions(driver);    
  
              // move the mouse to the earlier identified menu option
              builder.moveToElement(menu).build().perform();
  
              // wait for max of 5 seconds before proceeding. This allows sub menu appears properly before trying to click on it
              WebDriverWait wait = new WebDriverWait(driver, 5); 
              wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//a[@class='nav_a nav_item']")));  // until this submenu is found
  
              //identify menu option from the resulting menu display and click
              WebElement menuOption = driver.findElement(By.xpath("//a[@class='nav_a nav_item']"));
              menuOption.click();
  </code></pre>
  
  <p>Please tell me why its not working?</p>