RE: How to select sub menu by mouse hovering over the main menu?

I knew few of the concepts but still exploring new things like I am not able to detect how to write code for the selection of menu items from the main menu. I am unable to find the menu item element using  XPATH. Like for sample for the site www.toolsqa.com if I hover the mouse on “TUTORIALS” main menu the sub menu is shown.

 

 

 

 

I have written the code like as below and it is running successfully and detected the main menu “TUTORIALS”  but not able to detect the sub menu “Selenium”. I am finding difficulty to locate the menu item that needs to mouse over on could you please suggest me where the mistake is?

public static void main(String[] args) throws InterruptedException {

WebDriver driver= new FirefoxDriver();
driver.manage().window().maximize();
driver.get(“http://www.toolsqa.com/”);
Thread.sleep(5000);
//finding the main menu item “TUTORIALS” using XPATH
WebElement menu= driver.findElement(By.xpath(“.//*[@id=’main-nav’]/li[2]/a”));
Thread.sleep(5000);

//Move mouse pointer on drop down menu item “Selenium”
Actions actions= new Actions(driver);
actions.moveToElement(menu).perform();
driver.findElement(By.linkText(“Selenium”)).click();

}
}

 

 

When I tried to locate the menu item using FireBug it displays as below. Can’t we use “linktext” to locate the sub menu item?

 

 

 

Finally I am very sorry to bother you with my questions. Is it alright if I come with new questions ?

 

Thanks and regards,

Kavitha

KG Train Asked on September 5, 2015 in Selenium WebDriver.
Add Comment
4 Answers

Thank you very much really it worked.

Train Answered on September 6, 2015.

Welcome .

For further Queries please share the Screenshot so that it adds more info 🙂

on September 6, 2015.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.