1

I want to click the 'CookBooks' in following menu by using selenium web driver. It is appearing hovering the mouse and it is a javascript menu. Please help me . Following is the html view of that menu.

<li>
<a href="#">
<span>Set Up</span>
</a>
    <ul>
    <li>
        <a onclick="validateLevelOfOwnership('MaintainCookbook.html');return false;" href="javascript:void(0)">
        <span>Cookbooks</span>
        </a>
    </li>
    <li>
        <a onclick="validateLevelOfOwnership('MaintainCategories.html');return false;" href="javascript:void(0)">
        <span>Categories</span>
        </a>
    </li>
    <li>
        <a onclick="validateLevelOfOwnership('MaintainDistributors.html');return false;" href="javascript:void(0)">
        <span>Distributors</span>
        </a>
    </li>
    <li>
        <a href="/recipeManager/distributorItem/listItems.action">
        <span>Distributor Items</span>
        </a>
    </li>
        <li>
        <a onclick="validateLevelOfOwnership('MaintainPreparationMethodsAndConversions.html');return false;" href="javascript:void(0)">
        <span>Prep Methods & Conversion Ratios</span>
        </a>
        </li>
    </ul>
</li>

2 Answers 2

1

you can try the following code,

driver.findElement(By.linkText("Cookbooks")).click();

This can be used to click on text which represents links..

Sign up to request clarification or add additional context in comments.

Comments

0

You can use the 'Actions' class here to emulate the user gestures.

Below is the code I wrote to perform a menu click wherein we need to first hover the mouse over root menu and then click the sub-menu. For illustration purpose, I've taken the site : http://www.milonic.com/menusample15.php.

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

    WebDriver driver = new FirefoxDriver();
    driver.get("http://www.milonic.com/menusample15.php");

    //element refering to 'Milonic' menu
    WebElement rootMenu = driver.findElement(By.linkText("Milonic"));

    Actions action = new Actions(driver);

    //move to 'Milonic' first
    action.moveToElement(rootMenu).perform();
    //wait for the sub-menu to come up
    Thread.sleep(1000);
    //inside sub-menu click on 'FAQ'
    action.moveToElement(driver.findElement(By.linkText("FAQ"))).click().perform();
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.