samedi 25 avril 2015

sometimes move to element and click event is not working


I am new to selenium web driver and stuck with follows problem. I have written code for hover on Menu and click sub menu in jsp page.in this i have 3 anchor tags that are used to click and redirect to another page.

But the problem is first and last anchors are working properly not second tag. first and last tag action can achieve. But when driver moves to seconds tag which is not respond and says Exception as "No such Element".

How it is possible. Don't know why it doesn't move to that particular tag and trigger that.Kindly help me. Thanks in advance.

    <li style="z-index:1"><a href="welcome.jsp">Business</a>
    <ul><li><a href="ChainPerformance.jsp">Chain Performance</a>
<li><a href="TopXReport.jsp">Top X Report</a><li>
    <a href="ChainTop.jsp">Chain Top</a><li></ul></li>

Code for mouse hover and click:

@Then ("^I hover on (.+) menu and (.+) submenu$")
            public void mousehover(String elementName,String subMenu) throws InterruptedException{
                Actions actions = new Actions(webdriver);
                WebElement menuHoverLink = webdriver.findElement(By.xpath("//a[text() = '" + elementName + "']"));
                actions.moveToElement(menuHoverLink).perform();
                Thread.sleep(2000);
                actions.moveToElement(menuHoverLink).moveToElement(webdriver.findElement(By.xpath("//a[text() = '" + subMenu + "']")));
                Thread.sleep(2000);
                actions.click().perform();
                System.out.println("Sub menu "+subMenu+" Has been clicked");
            }


Aucun commentaire:

Enregistrer un commentaire