Mouseover over link not working with webdriver ...

752 views
Skip to first unread message

Rahul Singh

unread,
Oct 5, 2013, 3:00:49 PM10/5/13
to seleniu...@googlegroups.com
Hi,

I was creating a sample test using site www.flipkart.com, where one of the scenario actually gets failed. kindly help me to understand is there anything wrong with the code or something which i'm missing.
System data :
Browser : FF24
Webdriver version : 2.33
Win 7 (32 bit) and 64 bit machine

Code :

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;

public class Login {

public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.get("http://www.flipkart.com");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10L, TimeUnit.SECONDS);
Actions action = new Actions(driver);
action.moveToElement(driver.findElement(By.xpath("//ul[@class='menu-links']/li[2]"))).perform();
driver.findElement(By.xpath("//a[contains(@href,'hp_nmenu_sub_men_1_Watches')]")).click();
action = null;

driver.close();
driver.quit();
}
}


Cheers,
Rahul...

praveenreddy narala

unread,
Oct 7, 2013, 1:16:08 AM10/7/13
to seleniu...@googlegroups.com
Rahul,

Use this code..

WebElement element = driver.findElement(By.id("Element id"));
Locatable hoverItem = (Locatable) element;
Mouse mouse = ((HasInputDevices) driver).getMouse();
mouse.mouseMove(hoverItem.getCoordinates());

Rahul Singh

unread,
Oct 7, 2013, 3:32:14 AM10/7/13
to seleniu...@googlegroups.com
HI Praveen,

thanks for the reply but there seems to be an error in last line of the code :
mouse.mouseMove(hoverItem.getCoordinates());

eclipse is suggesting to typecating the hoveritem.getCoordinates with Locatable object. but it's still not working..

But things are working now as the matter of fact, Action class started working at my office machine. also there was one more solution (by using Robot class) which worked to moved the mouse but issue here is of finding the correct coordinates of the element on screen :|

But thanks again for your time :)

praveenreddy narala

unread,
Oct 7, 2013, 5:26:35 AM10/7/13
to seleniu...@googlegroups.com
Rahul,

This will give you the exact co-ordinates on the page not on screen. Some times we need to adjust the mouse move on to the location (like X + 30, Y + 100).

        org.openqa.selenium.Point coordinates = element.getLocation();
        Robot robot = new Robot();
        int X = ((Locatable)element).getLocationOnScreenOnceScrolledIntoView().getX();
        int Y = ((Locatable)element).getLocationOnScreenOnceScrolledIntoView().getY();
        robot.mouseMove(X + 30, Y + 100);
I think this will work for you.

Rahul Singh

unread,
Oct 7, 2013, 6:03:09 AM10/7/13
to seleniu...@googlegroups.com
Sure Praveen , will try this to find the location of the element. I've learned about the Robot class today itself courtsey a member of this group ( namely Nitesh ).

Thanks again to all of you :)

PS : Will share the updates later in the day



--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/7l2m6Ua4MQk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/65e8d12a-17ed-4dd0-b047-1317b7c2a431%40googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages