2

My requirement is verifying Image Hover is working or not using Webdriver. In that image tag title value is changing when I mouseover on the image like below.

Normal:
[img title="ASPIRIN" "src="http://img.med.com/pi/LNK01570.jpg" class="preview">

if i mouseover on that image:
[img title="" "src="http://img.med.com/pi/LNK01570.jpg" class="preview">

So here I'm trying to compare title values to verify the image hover. I have written code for that and it is working fine when I execute the script without using Grid. But using Grid mouseOver is not working properly. Image tag values aren't being changed. Is there any issue with using Grid? I'm using FF17 and Selenium 2.28.0 and Selenium 2.25.0.

My code:

String strVal1 = driver.findElement(By.xpath("//table[@id='ref_priceimgtable']/tbody/tr[12]/td[4]/img")).getAttribute("title");
        System.out.println(strVal1);
        WebElement element = driver.findElement(By.xpath("//table[@id='ref_priceimgtable']/tbody/tr[12]/td[4]/img"));
        Locatable hoverItem = (Locatable) element;
        hoverItem.getLocationOnScreenOnceScrolledIntoView();
        Mouse mouse = ((HasInputDevices) driver).getMouse(); 
        mouse.mouseMove(hoverItem.getCoordinates());
        String strVal2 = driver.findElement(By.xpath("//table[@id='ref_priceimgtable']/tbody/tr[12]/td[4]/img")).getAttribute("title");
        System.out.println(strVal1+"Null Value");

In the above code strVal1 and strVal2 should be different.

user1
  • 945
  • 2
  • 13
  • 37
Aayush
  • 116
  • 5
  • 14

1 Answers1

1

 String strVal1 =driver.findElement(By.xpath("//table[@id='ref_priceimgtable']/tbody/tr[12]/td[4]/img")).getAttribute("title");

        System.out.println(strVal1);

WebElement element = driver.findElement(By.xpath("//table[@id='ref_priceimgtable']/tbody/tr[12]/td[4]/img"));

Actions mouseOver = new Actions(driver);

mouseOver .moveToElement(element).build().perform(); 

String strVal2 = driver.findElement(By.xpath("//table[@id='ref_priceimgtable']/tbody/tr[12]/td[4]/img")).getAttribute("title");
        System.out.println(strVal1+"Null Value");

Have you tried this method for mouse over ? If you try this method means , have you called the method for firefox profile "profile.setEnableNativeEvents(true);" ? . the method is necessary to firefox to handle the mouse over in selenium .

Pls try this i think this works fine in grid too.

kks
  • 11
  • 4