1

I am trying to click a mouse hover link using the code below. The webdriver (v.2.35) doesn't throw any error but the element isn't clicked. Can somebody help me figure out what's wrong?

String URL = "http://www.kgisliim.ac.in/"
String menu ="Alumni>Register"

driver.get(URL);
String[] menuItems = menu.split(">");
Actions actions = new Actions(driver);
WebElement tempElem;
for (int i =0 ; i< menuItems.length ; i++) {                     
   tempElem =  driver.findElement(By.linkText(menuItems[i].trim()));
   actions.moveToElement(tempElem).build().perform();
}
actions.click();
actions.perform();

NOTE: The above code works fine in the below scenario

String URL = "http://www.flipkart.com/"
String menu ="Clothing>Jeans"
1
  • trying to click a mouse hover link... what? are you trying to hover? or click? what's the behavior you expect? Hover over this link, then click on something that appears? Commented Sep 26, 2013 at 18:56

3 Answers 3

1

You can try this:

WebDriver driver=new FirefoxDriver();
        driver.get("http://www.kgisliim.ac.in/");
        Actions  actions=new Actions(driver);
        WebElement menuHoverLink=driver.findElement(By.linkText("Alumni"));
        actions.moveToElement(menuHoverLink);
        //driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
        WebElement subLink=driver.findElement(By.cssSelector(".options>ul>li>a"));
        actions.moveToElement(subLink);
        actions.click();
        actions.perform();
Sign up to request clarification or add additional context in comments.

Comments

0

Since the menu on http://www.kgisliim.ac.in/ takes a second to slide out, you could add a WebDriverWait to make sure the submenu has time to become visible before moving the cursor to it. Try replacing the first line in your for loop with the following line. This will wait a maximum of 5 seconds for the submenu (but will return the WebElement as fast as possible within that time).

tempElem = new WebDriverWait(driver, 5).until(ExpectedConditions
        .elementToBeClickable(By.linkText(menuItems[i].trim())));

Comments

0

I stumbled across a similar issue recently, with phantomJS and ghostdriver. In my case, the problem was the window size - the HTML element was outside the visible area and my mouse movements were having no effect (default size is 400x300, which is rather small).

You can check the window size with

driver.manage().window().getSize()

And you can change it with

driver.manage().window().setSize(new Dimension(width, height));

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.