Display results as :
Advanced Search

Go down
Posts : 1
Join date : 2014-09-24

mouse hover doesn't work for safari and firefox browsers Empty mouse hover doesn't work for safari and firefox browsers

on Wed Sep 24, 2014 11:04 pm
//Find the achievements element without the number.  waitForElementXPath is wrapper I wrote using the function waitUntilExpectedConditions
WebElement achieveCircle = waitForElementXpath(webDriver,DEFAULT_WAIT_TIME,"html/body/div/div[2]/div/section/div/div/section/div[2]/div/span");

Assert.assertNotNull(achieveCircle,"achieveCircle not found."); 
//Hover over the element.
Actions builder = new Actions(webDriver);
Actions hover = builder.moveToElement(achieveCircle);
//Find the second achievement link
WebElement firstAchieve =  waitForElementXpath(webDriver,DEFAULT_WAIT_TIME,"/html/body/div/div[2]/div/section/div/div/section/div[2]/div/div/div/div[3]/div/div[2]/a");
//Verify that the link was found
Assert.assertNotNull(firstAchieve,"First achievement link not found"); 
//Move to the element and click on it in one step.
//Look for the new driving achievement box
WebElement driveText = waitForElementXpath(webDriver,DEFAULT_WAIT_TIME, "html/body/div[3]/div/div[2]/div[2]/div/div/div/div");
Assert.assertNotNull(driveText,"New Driving Achievement Text not found.");   
//Find the OK button.
//findElemByXpath() is another wrapper function I wrote that catches element not found exception.
WebElement achieveBtn = findElemByXPath(webDriver,"html/body/div[3]/div/div[2]/div[2]/div/div/div[2]/div/div[5]/a/span");
Assert.assertNotNull(achieveBtn,"Can't find OK button on New Driving Achievement box.");   
//Click on the OK button; 

//Wait for a web element to be visible up to the waitTime.
//webDriver is the selenium driver that was setup earlier.  waitTime is seconds.  xpath is X path of element to wait for.
public WebElement waitForElementXpath(WebDriver driver, int waitTime, String xpath)
    WebElement element;
    WebDriverWait wait = new WebDriverWait(driver, waitTime);
    //Catch the timeout exception if we don't find the element.
        element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpath)));
    catch (TimeoutException e)
        element = null;
    return element; 

//find web element by X path.
//webDrive is the driver setup earlier.  xpath is Xpath of element to search for.
public WebElement findElemByXPath(WebDriver webDriver, String xpath)
    //Use findElement and catch the not found exception.
        WebElement element = webDriver.findElement(By.xpath(xpath));
 return element;
    catch (WebDriverException e)
        return null;


I use the code above to hover over a circle containing the number of accomplishments and wait for 2 link elements to appear.  Then I move to one of the 2 link elements, click on it and wait for a popup box to appear.

The code works for the Chrome and IE browsers.

The code does not work for Firefox though.  The accomplishments circle is clicked and the link element appears.  However Selenium doesn't find them and the test fails.

For the Safari browser, I get an Exception "movemouseto command not recognized" when the hover.perform(); statement is executed.

I hope my code I've pasted is not too long.  I wrote 2 "wrapper" functions to wait for an element and another function to locate an element.

Thank you.
Active particpant
Active particpant
Posts : 10
Join date : 2014-07-24

mouse hover doesn't work for safari and firefox browsers Empty Re: mouse hover doesn't work for safari and firefox browsers

on Fri Oct 10, 2014 5:01 pm
Try to use this code
WebElement from= browser.findElement("draggable")); 
WebElement to = browser.findElement("droppable")); 
new Actions(browser).dragAndDrop(from, to).build().perform();

Automation COE,
Indium Software India Limited.
Test Automation
Back to top
Permissions in this forum:
You cannot reply to topics in this forum